Linux 我想使用“awk”或 sed 打印文件中所有以“comm=”开头的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8326817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I want to use "awk" or sed to print all the lines that start with "comm=" in a file
提问by wael
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"
我想使用“awk”或“sed”来打印comm=
从文件开始的所有行filex
,注意每一行都包含“comm=somthing”
for example : comm=rm , comm=ll, comm=ls ....
How can i achieve that ?
我怎样才能做到这一点?
回答by jaypal singh
For lines that start with comm=
对于以开头的行 comm=
sed -n '/^comm=/p' filex
awk '/^comm=/' filex
If comm=
is anywhere in the line then
如果comm=
在该行中的任何位置,则
sed -n '/comm=/p' filex
awk '/comm=/' filex
回答by Cédric Julien
回答by Michael J. Barber
Here's an approach using grep:
这是使用 grep 的一种方法:
grep -o '\<comm=[[:alnum:]]*\>'
This treats a word as consisting of alphanumeric characters; extend the character class as needed.
这将一个单词视为由字母数字字符组成;根据需要扩展字符类。
回答by nbari
If grep
is ok to use, you could give a try to:
如果grep
可以使用,您可以尝试:
grep -E "^comm=" file