Solved Remove Column from .Csv

April 2, 2015 at 09:55:33
Specs: Windows 7
Hi,

I am trying to remove the Column from .CSV using Awk Command. Below is the input

Name,Age,Description,Location
Gopal,32,Tech Lead,"Ramnagar, Naintal"
Gaurav,24,"Linux Admin, Expert","Noda"

I want column 1,2,4 and i am using below mention command

awk -F, ' BEGIN { OFS="," }
{
print $1,$2,$4
}' new.csv > new-done.csv


but instead of getting Gaurav,24,Noda

i am getting

Name,Age,Location
Gopal,32,"Ramnagar
Gaurav,24, Expert"


See More: Remove Column from .Csv

Report •

#1
April 3, 2015 at 06:28:06
✔ Best Answer
In this line:

Gaurav,24,"Linux Admin, Expert","Noda"

You are expecting the 3rd field to be:

"Linux Admin,Expert"

This is a bad assumption as far as awk is concerned. awk assumes the comma inside the double quoted string is another field seperator. That's why you aren't getting your required solution.

I have seen a perl regular expression solution for solving this sort of problem, but I think it'll be difficult with awk.

I might be able to look at this over the weekend if you can wait that long for a solution.


Report •
Related Solutions


Ask Question