【发布时间】:2019-10-30 14:56:24
【问题描述】:
我现在有大约 210 个 csv 文件,大小都在 28kb 左右,它们需要标头。我正在尝试在 iMac 的终端上使用sed 来完成此操作,但效果不佳。
我的命令的基本结构是:
sed '1 i\First Name,Last Name,Position,Company Name,Street Address,City,State,Zip Code,Phone Number,Cell Phone,Website,Email,Deal Name,Deal Stage,Deal Pipeline,Amount,Contact Owner,Deal Owner'/Users/me/Desktop/list/xab.csv
它正在吐出:
sed: 1: "1 i\First Name,Last Nam ...": extra characters after \ at the end of i command
我还尝试定义备份文件的扩展名:
sed '1 i ".bak"\First Name,Last Name,Position,Company Name,Street Address,City,State,Zip Code,Phone Number,Cell Phone,Website,Email,Deal Name,Deal Stage,Deal Pipeline,Amount,Contact Owner,Deal Owner'/Users/me/Desktop/list/xab.csv
满足以下条件:
sed: 1: "1 i " "\First Name,Last ...": command i expects \ followed by text
所以,我被困住了。有什么想法吗?
【问题讨论】:
-
在 'i\' 之后添加一个换行符。此外,您需要在参数中的文件名之前放置一个空格。
-
您将 sed “插入”指令
i与 sed “内联编辑”命令行参数-i混淆了。