【发布时间】:2021-05-16 02:40:55
【问题描述】:
我想使用$1 列中的值保存行并使用$1 中的值将行保存在一个文件中,如果它具有不同的值,请将其保存到另一个新文件中
112 14.7 114.98 -0.92 -0.12
112 14.8 114.02 -0.78 0.76
112 14.1 114.99 -0.98 -0.11
113 12.5 111.77 1.87 -1.88
113 12.6 111.89 -0.98 -1.65
115 15.7 110.8 2.06 0.72
118 11.9 111.01 -1.04 0.98
我想要的是
file1=p004112.txt
112 14.7 114.98 -0.92 -0.12
112 14.8 114.02 -0.78 0.76
112 14.1 114.99 -0.98 -0.11
file2=p004113.txt
113 12.5 111.77 1.87 -1.88
113 12.6 111.89 -0.98 -1.65
file3=p004115.txt
115 15.7 110.8 2.06 0.72
file4=p004118.txt
118 11.9 111.01 -1.04 0.98
必须像这样更改的文件具有名称文件p004.txt p005.txt
我试过这样for i in `ls p????.txt|sed "s/.txt//g"`;do awk '{file=${i}$1".txt" print >> file}' ${i}.txt;done
但它不起作用:(有人有这个问题的解决方案吗?
谢谢
【问题讨论】:
-
我试过
for i in `ls p????_s.txt | sed "s/.txt//g"`; do paste ${i}.txt | awk 'prev!=$1{close(outputFile);outputFile=(${i}"_"$1".txt")} {print > (outputFile);prev=$1}';done,但还是出错
标签: awk match multiple-columns newline