Hi Need a shell script to parse through the csv file – Line by line and then field by field ]
the file will look like this
X1,X2,X3,X4
Y1,Y2,Y3,Y4
I need to extract each of these X1,X2….
I wrote a script but it fails if the line exceeds one line..
Here’s how I would do it.
First i set the IFS environment variable to tell
readthat “,” is the field separator.Given the file “input” containing the data you provided, I can use the following code:
To quickly recap what is going on above.
cat test |reads the file and pipes it towhile.whileruns the code betweendoanddonewhilereadreturns true.readreads a line from standard input and separates it into variables (“a”, “b”, “c” and “d”) according to the value of $IFS. Finallyechojust displays the variables we read.Which gives me the following output
BTW, the BASH manual is always good reading. You’ll learn something new every time you read it.