Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete first column of csv file [duplicate]

Tags:

bash

sed

awk

I would like to know how i can delete the first column of a csv file with awk or sed

Something like this :

FIRST,SECOND,THIRD

To something like that

SECOND,THIRD

Thanks in advance

like image 970
Stoufiler Avatar asked Oct 24 '17 07:10

Stoufiler


People also ask

How do you delete duplicate records in CSV?

To remove duplicate rows, find the column that should be unique. Click the column header, and select Remove Duplicates. This will create a new dataset with only one row for each value.


2 Answers

Following awk will be helping you in same.

awk '{sub(/[^,]*/,"");sub(/,/,"")} 1'   Input_file

Following sed may also help you in same.

sed 's/\([^,]*\),\(.*\)/\2/'  Input_file

Explanation:

awk '                 ##Starting awk code here.
{
  sub(/[^,]*/,"")     ##Using sub for substituting everything till 1st occurence of comma(,) with NULL.
  sub(/,/,"")         ##Using sub for substituting comma with NULL in current line.
}
1                     ##Mentioning 1 will print edited/non-edited lines here.
'   Input_file        ##Mentioning Input_file name here.
like image 65
RavinderSingh13 Avatar answered Oct 21 '22 05:10

RavinderSingh13


Using awk

$awk -F, -v OFS=, '{$1=$2; $2=$3; NF--;}1' file
SECOND,THIRD
like image 28
Rahul Verma Avatar answered Oct 21 '22 04:10

Rahul Verma