1

I have a csv file which is in a form of

input.csv

1,AREA,"POLYGON((103.855 1.27267,103.856 1.27316,103.851 1.27506,103.853 1.27941,103.853 1.2793,103.852 1.27879,103.852 1.27639,103.851 1.27624,103.851 1.27634,103.851 1.27661,103.851 1.27699,103.852 1.27985,103.852 1.28138,103.853 1.28188,103.853 1.28189,103.853 1.28058,103.853 1.28044,103.853 1.28048,103.853 1.28084,103.853 1.28206,103.853 1.28216,103.853 1.28205,103.853 1.28205,103.854 1.28196,103.854 1.28209,103.855 1.28141,103.855 1.2813,103.855 1.28086,103.856 1.28001,103.859 1.28528,103.859 1.28555,103.859 1.28556,103.859 1.28586,103.859 1.28587,103.859 1.28629,103.859 1.28662,103.859 1.28669,103.87 1.28157,103.873 1.27787,103.871 1.27586,103.863 1.26996,103.862 1.26924,103.861 1.2689,103.86 1.26869,103.859 1.26884,103.858 1.26921,103.856 1.2702,103.855 1.27088,103.856 1.27227,103.855 1.27253,103.851 1.27428,103.852 1.2739,103.855 1.27267))"

I want to remove the third column which is not fixed in size. I tried with the

cut -d, -f3 --complement input.csv

But it is not working fine.Any help is appreciated.

1
  • If the first two fields are simple -- never containing quotes commas -- then cut -d, -f1-2 would do it
    – Jeff Schaller
    Dec 19, 2016 at 1:46

1 Answer 1

4

The cut tool is not smart enough to figure out that those commas in the third column are not delimiters.

You can however select a range of columns: in this case -f1-2 will select columns 1 through 2, thereby excluding 3.

However for general CSV processing you need a more powerful parser, such as those found in scripting languages like Python and Perl.

1
  • 1
    Yes cut -d, -f1-2 works perfectly
    – joker21
    Dec 19, 2016 at 1:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .