Having a CSV file like this:
HEADER
"first, column"|"second "some random quotes" column"|"third ol' column"
FOOTER
and looking for result like:
HEADER
first, column|second "some random quotes" column|third ol' column
in other words removing FOOTER
, quotes in beginning, end and around |
.
So far this code works:
sed '/FOOTER/d' csv > csv1 | #remove FOOTER
sed 's/^\"//' csv1 > csv2 | #remove quote at the beginning
sed 's/\"$//' csv2 > csv3 | #remove quote at the end
sed 's/\"|\"/|/g' csv3 > csv4 #remove quotes around pipe
As you see the problem is it creates 4 extra files.
Here is another solution, that has a goal not to create extra files and to do the same thing in a single script. It doesn't work very well.
#!/bin/ksh
sed '/begin/, /end/ {
/FOOTER/d
s/^\"//
s/\"$//
s/\"|\"/|/g
}' csv > csv4
sed
is not going to work with that, only with simplified csv. Use a programming language with a library that can handle real CSV files (Python/Perl/Ruby).