sed打印替换后的内容

关键字: sed, text process

一个文件,首先需要将某一特定行中的一些字符给删除,然后再将删除后的这一行内容打印出来,也不知道自己发什么神经不想用管道,反正在放狗N分钟后得到如下结果:

sed -n 's/^hostname:[ \t]*\(.*\)/\1/p' conf.ini

首先让sed进入安静模式,然后正则查找,把找到的那个东西\1打印出来,本来老想着先查找,再p,再替换,所以总是走不通。没想到s//后面还能跟p,真像那个man手册里面说的一样,sed的瑞士军刀啊。

This entry was posted in 小企鹅Linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>