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

后端 未结 4 1034
情歌与酒
情歌与酒 2021-01-02 03: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\"

相关标签:
4条回答
  • 2021-01-02 04:23

    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
    
    0 讨论(0)
  • 2021-01-02 04:29

    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.

    0 讨论(0)
  • 2021-01-02 04:30

    You could use grep also :

    grep comm= filex
    

    this will display all the lines containing comm=.

    0 讨论(0)
  • 2021-01-02 04:32

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

    grep -E "^comm=" file
    
    0 讨论(0)
提交回复
热议问题