我想在文件中用第一行(注意sed -e '1s/ /_/g' head_test.csv
中的1)替换没有下划线和括号的空格。
这是我正在使用的文件:
$ head -n 1 head_test.csv
"Rec Open Date","MSISDN","IMEI","Data Volume (Bytes)","Device Manufacturer","Device Model","Product Description"
这就是我使用sed实现它的方式
$ sed -e '1s/ /_/g' head_test.csv | sed -e '1s/(//g' | sed -e '1s/)//g' | head -n 1
"Rec_Open_Date","MSISDN","IMEI","Data_Volume_Bytes","Device_Manufacturer","Device_Model","Product_Description"
但我无法使用-i.bak
选项覆盖现有文件。任何人都可以使用-i选项建议我如何做到这一点。
答案 0 :(得分:0)
我建议将所有3个bodyParser: (function() {
var opts = { limit: '50mb' };
var fn;
// Default to built-in bodyParser:
fn = require('skipper');
return fn(opts);
}),
调用合并为1,然后添加sed
以在-i.bak
命令之前创建名为data.bak
的备份文件执行,也没有必要创建一个只有第一行的文件,即管道末端不需要sed
和最后head_test.csv
命令:
head
$ ls data*
data
$ cat data
"Rec Open Date","MSISDN","IMEI","Data Volume (Bytes)","Device Manufacturer","Device Model","Product Description"
abcd
xyz
$ sed -i.bak -e '1s/\s/_/g' -e '1s/(//g' -e '1s/)//g' data
$ cat data
"Rec_Open_Date","MSISDN","IMEI","Data_Volume_Bytes","Device_Manufacturer","Device_Model","Product_Description"
abcd
xyz
$ cat data.bak
"Rec Open Date","MSISDN","IMEI","Data Volume (Bytes)","Device Manufacturer","Device Model","Product Description"
abcd
xyz
$
表示就地编辑,即-i
执行文件数据上的所有命令,并保留文件中的所有更改,从而有效地更改文件内容
sed
1st创建文件的备份副本:-i.bak
,然后对filename.bak
进行更改