I want to use “awk” or sed to print all the lines

2020-02-28 04:21发布

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 ?

4条回答
Root(大扎)
2楼-- · 2020-02-28 04:51

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
查看更多
该账号已被封号
3楼-- · 2020-02-28 05:11

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楼-- · 2020-02-28 05:12

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

grep -E "^comm=" file
查看更多
爷的心禁止访问
5楼-- · 2020-02-28 05:17

You could use grep also :

grep comm= filex

this will display all the lines containing comm=.

查看更多
登录 后发表回答