gpt4 book ai didi

linux - 如何将额外值连接到一个命令的输出并将其传递给另一个 Unix 命令

转载 作者:太空宇宙 更新时间:2023-11-04 04:06:26 24 4
gpt4 key购买 nike

我有这个命令

grep 'Some pattern' location/*filename* | cut -d ' ' -f2 | cut -d '}' -f2 |
grep -v '^$' | head -1

上面的命令给我输出一些文件名,例如:

abc.txt

现在我想从这个文件 abc.txt 中 grep 另一行并匹配一些特定的模式,所以我这样做了

grep 'some pattern' location/*filename* | grep -iv .tar | grep -v backup |
grep -v bkp | cut -d ' ' -f2 | cut -d '}' -f2 | head -1 | xargs grep 'some pattern'

它不起作用,因为我的当前目录中不存在 abc.txt 文件。

有人可以告诉我如何在将 abc.txt 传递给 xargs grep 命令之前将其附加到位置路径吗?

最佳答案

你可以试试这个,

grep 'some pattern' location/*filename* | grep -iv .tar | grep -v backup |
grep -v bkp | cut -d ' ' -f2 | cut -d '}' -f2 | head -1 | xargs |
sed 's#.*#/path/to/dir/&#g' | xargs grep 'some pattern'

关于linux - 如何将额外值连接到一个命令的输出并将其传递给另一个 Unix 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21012867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com