I am facing one issue with my source file. Consider I have following data in file-
"dfjsdlfkj,fsdkfj,werkj",234234,234234,,"dfsd,etwetr"
here, the delimiter is comma, but some fields have comma as a part of data. Such fields are enclosed in double quotes. I want to extract few columns from the file.
If I use cut -d "," -f 1,3
then I am getting output like-
"dfjsdlfkj,werkj"
I suggest you to use a
csv
parser. For example, python has one as a built-in module, so you only have to import it:Assuming your example line is in an input file named
infile
, run the script as:That yields:
You could try the following:
where
input.txt
is your input file, andgetFields.awk
is: