LinuxQuestions.org
Review your favorite Linux distribution.
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-31-2009, 12:59 AM   #1
manya
Member
 
Registered: Apr 2004
Posts: 194

Rep: Reputation: 15
How to filter out number of lines which are not constant in numbers.


Hi Friends,

I am writing a script where I need to grep out number of lines, which are not fixed in numbers but starting and end lines of that para are constant.

e.g

Please block below URLs
http://...........
http:...........
234.87.98.30
.
.
.
.
.

End of Urls

any one has any idea how can I filter out those URLs or number of lines between "please block" and "end"
 
Old 12-31-2009, 01:22 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
show a better example, and describe and show clearly what you want as output.
 
Old 12-31-2009, 01:30 AM   #3
manya
Member
 
Registered: Apr 2004
Posts: 194

Original Poster
Rep: Reputation: 15
Well, I would like filter out the lines which keeps on varying so i can not use -A or -B syntax with grep.
so looking for other better option by which I can grep out those lines. The one clue I can see is since these lines always starts and ends with certain fixed lines, I could use that criteria to extract the lines?

say for example

# Para Starts from below
Please block below URLS.
http://abc.com
123.23.24.45
http://xyz.com/aere.php
.
.
.
.
.
.

end

# para ends

So in the above example if I could filter out the lines between "Please block" and "end" I guess I could achieve the goal but not sure how to extract the same with the help of grep.

Do let me know if you have any other solution.
 
Old 12-31-2009, 01:41 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by manya View Post
Well, I would like filter out the lines which keeps on varying so i can not use -A or -B syntax with grep.
so looking for other better option by which I can grep out those lines. The one clue I can see is since these lines always starts and ends with certain fixed lines, I could use that criteria to extract the lines?

say for example

# Para Starts from below
Please block below URLS.
http://abc.com
123.23.24.45
http://xyz.com/aere.php
.
.
.
.
.
.

end

# para ends

So in the above example if I could filter out the lines between "Please block" and "end" I guess I could achieve the goal but not sure how to extract the same with the help of grep.

Do let me know if you have any other solution.
http://www.ibm.com/developerworks/li...GX03&S_CMP=EDU -> see "Listing 3: Printing a range of lines".
 
Old 12-31-2009, 02:07 AM   #5
manya
Member
 
Registered: Apr 2004
Posts: 194

Original Poster
Rep: Reputation: 15
Would it be possible to achieve the same in Bash Script?
Please let me know if you find any alternative.
 
Old 12-31-2009, 02:45 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,096

Rep: Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978Reputation: 978
First you asked for grep, now you want bash ??? How about sed
Code:
sed '/Please block/,/^end/ d' somefile
 
Old 12-31-2009, 03:15 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Code:
awk -vRS="end" '{gsub(/Please block.*/,"")}1' file

Last edited by ghostdog74; 12-31-2009 at 03:17 AM.
 
Old 12-31-2009, 06:25 PM   #8
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 606

Rep: Reputation: 127Reputation: 127
Using awk, if a line begins with Please block below URLs set a flag.

If the flag is set, then write subsequent lines to another file

If a line begins with End of Urls then unset the flag.

End
 
  


Reply


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
How to filter lines Nortekman Linux - Newbie 3 04-01-2009 10:35 AM
adding constant (number) to a number in all rows skuz_ball Programming 2 05-20-2008 09:57 PM
filter out lines containing specific keywords from output kpachopoulos Linux - General 2 03-12-2007 08:29 PM
Is there a way to filter out all the comment lines in a configuration file... Akhran Linux - Newbie 3 12-07-2005 11:07 AM
How to filter lines from a text file Rascale Linux - Software 1 10-28-2003 12:46 PM


All times are GMT -5. The time now is 04:39 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