删除
grep 输出中的标签我有一个 bash 脚本,它将在目录中的 .htm 或 .html 文件中查找电话号码(或者如果我想要的话,可以递归地向下)查找格式为 (ddd)ddd-dddd 或 ddd-ddd-dddd 的电话号码(其中d 代表数字)。
这是我的代码:
find ./ -maxdepth 1 -regex ".*\(html\|htm\)$" | xargs grep '\(([0-9]\{3\})\|[0-9]\{3\}\)[-]\?[0-9]\{3\}-[0-9]\{4\}'
输出是:
./dash_only_phone.htm:800-555-1212</p>
./paren_phone.htm:(800)555-1212</p>
我想知道如何更改 grep 命令以删除末尾的 html p 标签打印输出。
谢谢,
I have I bash script that will find phones numbers inside .htm or .html files in a directory (or recursivly down if I want it) to find phone numbers in the format (ddd)ddd-dddd or ddd-ddd-dddd (Where d represents a digit).
This is my code:
find ./ -maxdepth 1 -regex ".*\(html\|htm\)$" | xargs grep '\(([0-9]\{3\})\|[0-9]\{3\}\)[-]\?[0-9]\{3\}-[0-9]\{4\}'
The output is:
./dash_only_phone.htm:800-555-1212</p>
./paren_phone.htm:(800)555-1212</p>
I was wondering how I would change the grep command to remove the html p tag printout at the end.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的
grep
支持 Perl 兼容正则表达式,GNU 和 OS Xgrep
也支持:请注意转义中的更改(与
grep 类似或相同) -E
)。If your
grep
supports Perl Compatible Regular Expressions, as do GNU and OS Xgrep
:Note the changes in escaping (which are similar to or the same as for
grep -E
).为什么不直接通过
sed
过滤器传递输出来删除它,如以下记录所示:这将删除出现在一行的末尾。
Why not just pass the output through a
sed
filter to remove it, as in the following transcript:This will get rid of any
</p>
sequences that appear at the end of a line.您只需添加
-o
开关即可获取 IPYou can just add the
-o
switch to get the IP