在 linux 中使用 tac 命令在多个文件中查找和反转文本

find and reverse text in multiple files with tac command in linux

我正在尝试颠倒多个文本文件(用于绘图目的)的顺序,这些文本文件本质上是数字行。我试着用 tac 来做,并将它与 find-exec 结合起来作为

find ./dir1/dir2/ -name foo.txt -type f -exec tac {} \;

但这只会在屏幕上提供输出,不会修改预期的文件。

我是不是漏掉了什么?

您就快完成了 - tac 写入 stdout 这样您就可以简单地将输出重定向到方便的地方:

find .... \; > newfoo.txt

如果您希望将每个文件反转并写入同一位置,可以这样做:

find . -type f -exec sh -c 'tac "" > ""-new' -- {} \;

干杯,