【问题标题】:How to find an expression and replace with the file name for a .txt in bash using xargs and sed?如何使用 xargs 和 sed 在 bash 中查找表达式并替换为 .txt 的文件名?
【发布时间】:2015-11-05 04:36:20
【问题描述】:

我想在特定文件中查找表达式并将其替换为脚本中使用的文件的当前名称。我当前的脚本是:

for FILE in ../pdb/*; 

    do

    basename $FILE .pdb | xargs -I '{}' sed -i  's/_final.pdb/{}_final.pdb/g' ./temp.txt

    ./program < temp.txt

    done

psfgen.inp 中的输出包含每个文件的名称,而不仅仅是当前文件:

写pdb文件AfileBfileC_final.pdb

它应该喜欢:

写pdb文件A_final.pdb

如何替换 temp.txt 中当前的 basename,让程序在从循环中写入下一个 basename 之前使用 temp.txt,而不是在执行程序之前写入文件夹中所有文件的 basename?

谢谢!

【问题讨论】:

    标签: bash sed xargs


    【解决方案1】:

    好的,答案只是像这样替换整行:

    for FILE in ../pdb/*; 
    
        do
    
        basename $FILE .pdb | xargs -I '{}' sed -i  '/_final.pdb/c\writepdb {}_final.pdb' ./temp.txt
    
        ./program < temp.txt
    
        done
    

    【讨论】:

      猜你喜欢
      • 2020-04-22
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2015-04-01
      相关资源
      最近更新 更多