Delete first column of csv file

11,999

Solution 1

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.

Solution 2

With Sed

sed -i -r 's@^\w+,@@g' test.csv

Grab the begin of the line ^, every character class [A-Za-z0-9] and also underscore until we found comma and replace with nothing. Adding g after delimiters you can do a global substitution.

Solution 3

Using awk

$awk -F, -v OFS=, '{$1=$2; $2=$3; NF--;}1' file
SECOND,THIRD
Share:
11,999
Stoufiler
Author by

Stoufiler

Updated on June 30, 2022

Comments

  • Stoufiler
    Stoufiler over 1 year

    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