LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Need Grep command for the following output (https://www.linuxquestions.org/questions/programming-9/need-grep-command-for-the-following-output-397527/)

minil 12-29-2005 06:29 AM

Need Grep command for the following output
 
Hi
i need grep command for the following output.
I have a file. as given below

Code:

#192.168.48.155
10.0.0.4
      #11.0.0.1

#239.0.01
      #12.1.0.1
        192.168.48.172
192.168.48.100

#192.158.32.0

Questions as follows
  • To print lines which starts with # character.(# as first character .No space shoule be there #character). Output should be(Idont want blank lines.
    Code:

    #192.168.48.155
    #239.0.01
    #192.158.32.0

  • To print lines which with # character as first character in line and also line with any number of space followed by #character. output should be.
    Code:

    #192.168.48.155
          #11.0.0.1
    #239.0.01
          #12.1.0.1
    #192.158.32.0

  • To print lines which starts only with space character followed by # as first . Output should be as follows
    Code:

        #11.0.0.1
        #12.1.0.1

  • To print lines which contains space followed by any characters
    Code:

          #11.0.0.1
          192.168.48.172
          #12.1.0.1

Its urgent..
Thanks in advance.

druuna 12-29-2005 06:49 AM

Quote:

Originally Posted by minil
Questions as follows[list][*] To print lines which starts with # character.(# as first character .No space shoule be there #character). Output should be(Idont want blank lines.
Code:

#192.168.48.155
#239.0.01
#192.158.32.0


grep "^#" <infile>

Quote:

[*]To print lines which with # character as first character in line and also line with any number of space followed by #character. output should be.
Code:

#192.168.48.155
      #11.0.0.1
#239.0.01
      #12.1.0.1
#192.158.32.0


grep "^[ ]*#" <infile> (between the square brackets are a space and a tab)

Quote:

[*]To print lines which starts only with space character followed by # as first . Output should be as follows
Code:

    #11.0.0.1
    #12.1.0.1


grep "^[ ][ ]*#" <infile> (again, space and tab between the square brackets)

Quote:

[*]To print lines which contains space followed by any characters
Code:

      #11.0.0.1
      192.168.48.172
      #12.1.0.1


grep "^[ ][ ]*" <infile> (again, space and tab between the square brackets)

Hope this helps.

minil 12-29-2005 07:49 AM

Thank you very much druuna


All times are GMT -5. The time now is 04:10 AM.