【发布时间】:2015-10-26 04:18:51
【问题描述】:
我有两个测试文件,ttt.txt和ttt2.txt,内容如下:
#ttt.txt
(132) 123-2131
543-732-3123
238-3102-312
#ttt2.txt
1
2
3
我已经在 bash 中尝试过以下命令,效果很好:
if grep -oE "(\(\d{3}\)[ ]?\d{3}-\d{4})|(\d{3}-\d{3}-\d{4})" ttt1.txt ; then echo "found"; fi
# with output 'found'
if grep -oE "(\(\d{3}\)[ ]?\d{3}-\d{4})|(\d{3}-\d{3}-\d{4})" ttt2.txt ; then echo "found"; fi
但是当我将上述命令与 xargs 结合使用时,它会报错“-bash: syntax error near unexpected token `then'”。谁能给我一些解释?提前致谢!
ll | awk '{print $9}' | grep ttt | xargs -I $ if grep --quiet -oE "(\(\d{3}\)[ ]?\d{3}-\d{4})|(\d{3}-\d{3}-\d{4})" $; then echo "found"; fi
【问题讨论】: