我有一个 for 循环,它接受具有一种扩展名类型的文件,但管道中的最终命令要求 STDIN 文件具有另一种类型的扩展名。在我的管道中,我使用
awk
更改文件类型,以便其格式适合最终命令,但扩展名仍链接到初始输入文件。
例如:
for file in *.AAA
do
commandA $file | awk ' { print } ' | commandB
命令B的典型用法:
commandB -i myfile.BBB
有没有办法让我在 for 循环和管道中间更改文件的扩展名?
我认为你可以在 for 循环和管道中间更改文件的扩展名
for file in *.AAA
do
new_file="${file%.*}.BBB" #change the extension to .BBB
commandA "$file" | awk '{ print }' | commandB -i "$new_file"
或者您可以使用进程替换:
for file in *.AAA; do
commandA "$file" | awk '{ print }' | commandB -i <(commandA "$file" | awk '{ print }' | sed 's/\.AAA$/.BBB/')
done