我有一个CSV文件' 1.txt'字段为
#1.txt
Name,Activity,Address,URL,Number,Company
我希望采用格式
#2.txt
Name,URL,Address,Activity,Number,Company
我尝试过使用剪切
cut -d, -f1,4,3,2,5,6 1.txt > 2.txt
输出(2.txt
)与输入保持一致。
有人可以帮助我吗?由于文件大小太大(500000行)要处理工作表/ excel。
答案 0 :(得分:3)
根据test.rs:27:37: 27:40 error: `api` does not live long enough
test.rs:27 let worker = Box::new(Worker::new(api.as_ref()));
^~~
test.rs:25:19: 29:3 note: reference must be valid for the lifetime 'a as defined on the block at 25:18...
test.rs:25 fn new() -> Self {
test.rs:26 let api = Box::new(Api);
test.rs:27 let worker = Box::new(Worker::new(api.as_ref()));
test.rs:28 Engine { api: api, worker: worker }
test.rs:29 }
test.rs:26:27: 29:3 note: ...but borrowed value is only valid for the block suffix following statement 0 at 26:26
test.rs:26 let api = Box::new(Api);
test.rs:27 let worker = Box::new(Worker::new(api.as_ref()));
test.rs:28 Engine { api: api, worker: worker }
test.rs:29 }
error: aborting due to previous error
联机帮助页,所选输入的编写顺序与读取的顺序相同。所以你必须使用awk:
cut
答案 1 :(得分:3)
没有必要对每个字段编号进行硬编码,只需交换您关心的2个字段:
$ awk 'BEGIN{FS=OFS=","} {t=$2;$2=$4;$4=t} 1' file
Name,URL,Address,Activity,Number,Company