【发布时间】:2014-01-13 22:16:24
【问题描述】:
我在一个目录中有一堆文件, 我需要将“AB_”等文件中的行前缀更改为“YZ_” 我该怎么做?
我用过 grep 和 sed 之类的,
grep -nr "AB_" ./ | xargs -0 sed -i 's/AB_/YZ_/g'
但给出错误,
: File name too long
文件中的示例字符串为:Hello AB_WORLD! 和 Hello WORLD_AB!
谢谢。
【问题讨论】:
-
en.wikipedia.org/wiki/Xargs: 对 xargs 使用 -0 可以解决这个问题,但是许多 Unix 实用程序不能使用 NUL 作为分隔符(例如 head、tail、ls、echo、sed、tar -v、wc, )。