【发布时间】:2022-11-17 03:05:14
【问题描述】:
以下作品:
awk '
NR==FNR { sub(/\.(png|txt|jpg|json)$/,""); a[$0]; next }
{ f=$0; sub(/\.(png|txt|jpg|json)$/,"", f) }
!(f in a)
' comp1.txt comp2.txt > result.txt
现在我想让它把比较中应该忽略的文件结尾作为一个变量,但不能让它工作。我下面的尝试只是在不忽略任何文件结尾的情况下进行比较。我尝试使用 $ 和不使用,使用 () 和不使用,转义 |,但到目前为止没有成功。什么是正确的解决方案?
fileEndingsToIgnore="png|txt|jpg|json"
awk -v fileEndingsToIgnore="${fileEndingsToIgnore}" '
NR==FNR { sub(/\.(fileEndingsToIgnore)$/,""); a[$0]; next }
{ f=$0; sub(/\.(fileEndingsToIgnore)$/,"", f) }
!(f in a)
' comp1.txt comp2.txt > result.txt
【问题讨论】:
标签: awk