在终端中使用 AWK 在 CSV 中添加列标题

Mic*_*ael 2 unix linux csv terminal awk

您好,我正在尝试在终端中使用 awk 在我的 CSV 文件中添加列标题。

目前显示:

Michael, Michael@email.com, Seattle, Washington, detail1, detail2, detail3
Run Code Online (Sandbox Code Playgroud)

所需格式:

Name, Email, City, State, more1, more2, more3etc
Michael, Michael@email.com, Seattle, Washington, detail1, detail2, detail3,
Run Code Online (Sandbox Code Playgroud)

已经尝试过这样的事情,但我最终得到了“源代码第 2 行的非法声明”:

awk 'BEGIN {FS=",";OFS=","; print "Rating,Restaurant,Address,Landline,Mobile,Cuisine,Website,LatDD,LonDD"}
NR >1 {print ",",,,",",",", }' Restaurants.txt > Restaurants_newer.txt
Run Code Online (Sandbox Code Playgroud)

kar*_*kfa 5

这会做

sed '1iName, Email, City, State, more1, more2, more3etc' file > newfile
Run Code Online (Sandbox Code Playgroud)

也可以就地完成

sed -i '1iName, Email, City, State, more1, more2, more3etc' file
Run Code Online (Sandbox Code Playgroud)

或者

{ echo 'Name, Email, City, State, more1, more2, more3etc'; cat file; } > newfile
Run Code Online (Sandbox Code Playgroud)