将 sed 行分隔符更改为 NUL 以充当“xargs -0”预过滤器?
我正在运行这样的命令行:
filename_listing_command | xargs -0 action_command
其中 filename_listing_command
使用空字节来分隔文件 - 这就是 xargs -0
想要使用的内容。
问题是我想过滤掉一些文件。像这样的事情:
filename_listing_command | sed -e '/\.py/!d' | xargs ac
但我需要使用 xargs -0 。
如何将 sed 想要的行分隔符从换行符更改为 NUL?
I'm running a command line like this:
filename_listing_command | xargs -0 action_command
Where filename_listing_command
uses null bytes to separate the files -- this is what xargs -0
wants to consume.
Problem is that I want to filter out some of the files. Something like this:
filename_listing_command | sed -e '/\.py/!d' | xargs ac
but I need to use xargs -0
.
How do I change the line separator that sed wants from newline to NUL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您已经点击此 SO 来寻找答案,并且正在使用 GNU sed 4.2.2 或更高版本,那么它现在有一个 -z 选项,可以满足 OP 的要求。
If you've hit this SO looking for an answer and are using GNU sed 4.2.2 or later, it now has a -z option which does what the OP is asking for.
通过
grep
进行管道传输:-z
在输入上接受空终止符,-Z
在输出上生成空终止符,-v
反转匹配(排除)。编辑:
如果您更喜欢使用
sed
,请尝试以下操作:Pipe it through
grep
:The
-z
accepts null terminators on input and the-Z
produces null terminators on output and the-v
inverts the match (excludes).Edit:
Try this if you prefer to use
sed
:如果您的文件名都不包含换行符,那么使用 GNU Parallel 阅读解决方案可能会更容易:
了解有关 GNU Parallel 的更多信息 http://www.youtube.com/watch?v=OpaiGYxkSuQ
If none of your file names contain newline, then it may be easier to read a solution using GNU Parallel:
Learn more about GNU Parallel http://www.youtube.com/watch?v=OpaiGYxkSuQ
在汤姆·黑尔的帮助下< /a> 和那个我们有答案:
<代码>
sed -nzE "s/^$PREFIX(.*)/\1/p"
With help of Tom Hale and that answer we have:
sed -nzE "s/^$PREFIX(.*)/\1/p"