I have a csv for which I have to extract a specific field. The csv is pipe-delimited (
|), with double quotes (
") to protect text fields and (this is the catch) newlines in some of the text.
"aaa"|"111"|"!!!"|"" "bbb"|"222"|"@@ @"|"" "ccc"|"333"|"###"|""
I would like to extract the second field of each record:
111 222 333
I am using a bash script to read the file, but it seems the
read command stops when it reaches a newline, even when
-d is specified. That means, in the above example, that my script processes record 1 correctly (I use
read -d \| varname), but not record 2, because it doesn't recognise the newline as part of the third field. Now it sees
@"|"" as a new record and everything gets messy.
Is it at all possible to use
read for this, or should I look at alternatives?
I've spent DAYS playing around with
read's settings and searching on the web. Funny thing, I came across someone with a problem on the exact same kind of input file that I have, but that problem was with Excel.