LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-29-2005, 06:29 AM   #1
minil
Member
 
Registered: Dec 2004
Location: Bangalore, India
Distribution: Fedora 2
Posts: 74

Rep: Reputation: 15
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.
 
Old 12-29-2005, 06:49 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
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.
 
Old 12-29-2005, 07:49 AM   #3
minil
Member
 
Registered: Dec 2004
Location: Bangalore, India
Distribution: Fedora 2
Posts: 74

Original Poster
Rep: Reputation: 15
Thank you very much druuna
 
  


Reply

Tags
grep


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Grep command for the following output minil Programming 1 12-29-2005 06:51 AM
output to a file - cat? grep? Godsmacker777 Linux - Newbie 6 12-08-2004 10:06 AM
sort grep output wijnands Linux - Newbie 4 10-09-2004 07:14 AM
trying to figure out some output from grep naijaguy Linux - Newbie 8 08-17-2004 12:44 PM
How can I filter the output of grep to exclude certain cases? QtCoder Linux - General 1 03-28-2004 12:05 AM


All times are GMT -5. The time now is 11:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration