I want to use “awk” or sed to print all the lines that start with “comm=” in a file

♀尐吖头ヾ 提交于 2020-03-13 06:06:30

问题


I want to use "awk" or "sed" to print all the lines that start with comm= from the file filex, Note that each line contains "comm=somthing"

for example : comm=rm , comm=ll, comm=ls  ....

How can i achieve that ?


回答1:


For lines that start with comm=

sed -n '/^comm=/p' filex

awk '/^comm=/' filex

If comm= is anywhere in the line then

sed -n '/comm=/p' filex

awk '/comm=/' filex



回答2:


You could use grep also :

grep comm= filex

this will display all the lines containing comm=.




回答3:


Here's an approach using grep:

grep -o '\<comm=[[:alnum:]]*\>'

This treats a word as consisting of alphanumeric characters; extend the character class as needed.




回答4:


If grep is ok to use, you could give a try to:

grep -E "^comm=" file


来源:https://stackoverflow.com/questions/8326817/i-want-to-use-awk-or-sed-to-print-all-the-lines-that-start-with-comm-in-a-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!