删除csv文件的第一列

Sto*_*ler 4 bash awk sed

我想知道如何使用awk或sed删除csv文件的第一列

像这样的东西:

FIRST,SECOND,THIRD
Run Code Online (Sandbox Code Playgroud)

对于这样的事情

SECOND,THIRD
Run Code Online (Sandbox Code Playgroud)

提前致谢

Rav*_*h13 10

跟随awk将同样帮助您。

awk '{sub(/[^,]*/,"");sub(/,/,"")} 1'   Input_file
Run Code Online (Sandbox Code Playgroud)

遵循sed可能也有帮助。

sed 's/\([^,]*\),\(.*\)/\2/'  Input_file
Run Code Online (Sandbox Code Playgroud)

说明:

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.
Run Code Online (Sandbox Code Playgroud)

  • 2 个 `sub` 调用可以通过 `sub(/[^,]*,/,"")` 组合成一个 (2认同)