9.4.7 adshparsecsv command (analyzing CSV data)
Syntax
adshparsecsv [-e] array-name
Description
This command is a command that is used with script development parts. We recommend using parts for making CSV operation of script development parts when analyzing CSV data.
This command stores the CSV data that is loaded from the standard input in the two-dimensional array. Specifically, this command stores data delimited by comma as the value of each element of two-dimensional array. The size of the CSV data that can be input is 100KB or less. If you input data larger than 100KB, the execution time of the job may become longer.
Examples of the correspondence between elements of CSV data and the two-dimensional array are as follows:
- CSV data (data.csv)
-
name,value,id "Yokohama",200,0001 "Kawasaki",100,0002
- Correspondence between the two-dimensional array (array) and CSV data (data.csv)
-
array[0][0]=name array[0][1]=value array[0][2]=id array[1][0]="Yokohama" array[1][1]=200 array[1][2]=0001 array[2][0]="Kawasaki" array[2][1]=100 array[2][2]=0002
Arguments
- -e
-
This command interprets a double quotation mark included in the CSV data as a metacharacter.
- array-name ~ <environment variable name>
-
This command specifies the name of array in which the data is stored.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Termination with an error |
Example
CSV data(data.csv) name,value,id "Yokohama",200,0001 "Kawasaki",100,0002 # Stores the CSV data in the two-dimensional array. adshparsecsv array < data.csv echo "${array[1][0]}" # "Yokohama" is output. echo "${array[1][1]}" # "200" is output. # Interprets any double quotation marks included in the CSV data as metacharacters, and stores them in the two-dimensional array. adshparsecsv -e array < data.csv echo "${array[1][0]}" # "Yokohama" is output. echo "${array[1][1]}" # "200" is output.