Bash:“xargs cat”,在每个文件后添加换行符

发布于 2024-09-04 06:01:29 字数 275 浏览 5 评论 0原文

我使用一些命令来cat一些文件,如下所示:

 cat somefile | grep example | awk -F '"' '{ print $2 }' | xargs cat

它几乎可以工作,但我的问题是我想在每个文件后添加换行符。

这可以在一个衬垫中完成吗?

(当然我可以创建一个新的脚本或函数来执行cat,然后echo -n,但我想知道是否可以通过其他方式解决这个问题)

I'm using a few commands to cat a few files, like this:

 cat somefile | grep example | awk -F '"' '{ print $2 }' | xargs cat

It nearly works, but my issue is that I'd like to add a newline after each file.

Can this be done in a one liner?

(surely I can create a new script or a function that does cat and then echo -n but I was wondering if this could be solved in another way)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

墨小墨 2024-09-11 06:01:29
cat somefile | grep example | awk -F '"' '{ print $2 }' | while read file; do cat $file; echo ""; done
cat somefile | grep example | awk -F '"' '{ print $2 }' | while read file; do cat $file; echo ""; done
懒猫 2024-09-11 06:01:29

使用 GNU Parallel http://www.gnu.org/software/parallel/ 它可能更快(取决于您的系统):

cat somefile | grep example | awk -F '"' '{ print $2 }' | parallel "cat {}; echo"

Using GNU Parallel http://www.gnu.org/software/parallel/ it may be even faster (depending on your system):

cat somefile | grep example | awk -F '"' '{ print $2 }' | parallel "cat {}; echo"
我为君王 2024-09-11 06:01:29

awk -F '"' '/example/{ system("cat " $2 };printf "\n"}' somefile

awk -F '"' '/example/{ system("cat " $2 };printf "\n"}' somefile

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文