bash paste: 根据通配符遍历成对的文件,生成单独的输出文件

bash paste: loop through pairs of files based on wildcard, generate separate output files

我正在尝试让粘贴命令循环遍历成对的文件,将它们粘贴在一起并将每个文件输出为一个唯一的文件。 我已经尝试了很多东西,这里有一些:

 for i in *_temp4.csv; do paste *_temp4.csv *_temp44.csv > ${i}_out.csv; done
 #Each output contains each input file (rather than pairs). Obviously this is because of the * wildcard

 for i in *_temp2.csv_temp4.csv; do paste $_temp2_temp4.csv $_temp3_temp44.csv > ${i}_out.csv; done

没有错误,输出文件为空

 for i in *_temp2.csv_temp4.csv; do paste ${_temp2_temp4.csv} ${_temp3_temp44.csv} > ${i}_out.csv; done

输出:

 combo15.awk: line 12: ${_temp2_temp4.csv}: bad substitution

我想我一定遗漏了一些关于如何使用 $ 的非常基本的东西,但我整晚都在谷歌上搜索无济于事。

我的整个代码,为了上下文,虽然我不明白为什么前面的几行会影响这件事。

 for i in *.dat; do awk 'NR > 23 { print }' ${i} > ${i}_temp1.csv; done

 for i in *_temp1.csv; do awk 'BEGIN{OFS=FS=","}==0{="between"}BEGIN{OFS=FS=","}==1{="lego"}BEGIN{OFS=FS=","}==2{="pin"}BEGIN{OFS=FS=","}==3{="dice"}BEGIN{OFS=FS=","}==4{="jack"}BEGIN{OFS=FS=","}==8{="escape"}{print}'  ${i} > ${i}_temp2.csv; done

 for i in *_temp2.csv; do awk -v OFS="," '{ =  - prev1; prev1 = ; print;}' ${i} > ${i}_temp3.csv; done  

 for i in *_temp2.csv; do awk -F "," 'BEGIN{print "new line"}{print }' ${i} > ${i}_temp4.csv; done

 for i in *_temp3.csv; do awk -F "," '{print }' ${i} > ${i}_temp44.csv; done

 for i in *_temp2.csv_temp4.csv; do paste $_temp2_temp4.csv    $_temp3_temp44.csv > ${i}_out.csv; done

您的问题是,您的文件名不受控制地增长。此更改应该可以解决此问题:

for i in *.dat; do awk 'NR > 23 { print }' ${i} > ${i}_temp1.csv; done

for i in *.dat; do awk 'BEGIN{OFS=FS=","}==0{="between"}BEGIN{OFS=FS=","}==1{="lego"}BEGIN{OFS=FS=","}==2{="pin"}BEGIN{OFS=FS=","}==3{="dice"}BEGIN{OFS=FS=","}==4{="jack"}BEGIN{OFS=FS=","}==8{="escape"}{print}'  ${i}_temp1.csv > ${i}_temp2.csv; done

for i in *.dat; do awk -v OFS="," '{ =  - prev1; prev1 = ; print;}' ${i}_temp2.csv > ${i}_temp3.csv; done

for i in *.dat; do awk -F "," 'BEGIN{print "new line"}{print }' ${i}_temp2.csv > ${i}_temp4.csv; done

for i in *.dat; do awk -F "," '{print }' ${i}_temp3.csv > ${i}_temp44.csv; done

for i in *.dat; do paste ${i}_temp4.csv    ${i}_temp44.csv > ${i}_out.csv; done