在xargs命令相结合不同的正则表达式 [英] Combine different regex together in xargs command

查看:442
本文介绍了在xargs命令相结合不同的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这两个正则表达式:

I have these two regexes:

find ... | xargs perl -pi -e 's/\t/    /g'
find ... | xargs perl -pi -e 's/[^\S\n]+$//g'

首先一个人改变制表符为4个空格,而第二个在每行的末尾删除任何尾部的空白。

First one changes tabs to 4 spaces, and second removes any trailing white space at the end of each line.

我很想把两者结合起来,但不想碰坏。此外,他们在做不同的事情 - 一个是增加空间,另一种是去掉空格。有没有这两个合并在一起,或只是让他们作为是一种安全的方式?

I am tempted to combine the two, but don't want to break something. Besides, they are doing different things -- one is adding spaces, another is removing spaces. Is there a safe way to merge these two together or just leave them as is?

推荐答案

您可以这样做:

find ... | xargs perl -l -pi -e 's/\t/    /g; s/\s+$//'

由于第二找到在第一个结果是经营,它是安全连续在一个单一的执行每个命令 perl的调用。

Since the second find is operating on the results of the first one, it's safe to perform each command in succession in a single perl invocation.

这篇关于在xargs命令相结合不同的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆