【发布时间】:2012-10-23 14:53:45
【问题描述】:
我有一个用于组合 2 个文件的 awk 代码,并使用“>>”将结果添加到 file.txt 的末尾
我的代码
NR==FNR && $2!=0 {two[$0]++;j=1; next }{for(i in two) {split(i,one,FS); if(one[3] == $NF){x=$4;sub( /[[:digit:]]/, "A", $4); print j++,$1,$2,$3,x,$4 | "column -t" ">>" "./Desktop/file.txt"}}}
我想把我的 awk 放到 bash 脚本中,最后对我的 file.txt 进行排序,然后使用>再次将排序结果保存到 file.txt
我试过了
#!/bin/bash
command=$(awk '{NR==FNR && $2!=0 {two[$0]++;j=1; next }{for(i in two) {split(i,one,FS); if(one[3] == $NF){x=$4;sub( /[[:digit:]]/, "A", $4); print $1,$2,$3,$4 | "column -t" ">>" "./Desktop/file.txt"}}}}')
echo -e "$command" | column -t | sort -s -n -k4 > ./Desktop/file.txt
但它给了我错误"for reading (no such a file or directory)"
我的错误在哪里?
提前致谢
【问题讨论】:
-
你能给出输入文件和预期结果的例子吗?