简体   繁体   中英

How to grep only one line with matching one string. BASH

I want to grep only one line from below example:

    STRING1     EXAMPLE1   EXAMPLE2
    STRING2     EXAMPLE1   EXAMPLE2
    STRING3     EXAMPLE1   EXAMPLE2

I want to have only output from grep command:

    STRING3     EXAMPLE1   EXAMPLE2

Which argument I need to do in grep command to grep only "STRING3"?

Thank you for help.

I want to grep only one line from below example:

    STRING1     STRING3-EXAMPLE1   EXAMPLE2-STRING3
    STRING2     STRING3-EXAMPLE1   EXAMPLE2-STRING3
    STRING3     STRING3-EXAMPLE1   EXAMPLE2-STRING3

I want to have only output from grep command:

    STRING3     EXAMPLE1   EXAMPLE2

Which argument I need to do in grep command to grep only "STRING3"?

Thank you for help.

First, your question should be better defined and always remember that you don't need to post an answer to clarify things, you can edit your quest.

Regarding your question you should use grep to filter lines that start with STRING3 in your case you have 4 spaces and then STRING3 so you should keep that in mind.

grep '^    STRING3' test.txt

Overall I would suggest using sed or awk instead of grep because your case seems a bit complicated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM