LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 06-09-2009, 08:34 PM   #1
packets
Member
 
Registered: Oct 2005
Posts: 339

Rep: Reputation: 32
grep only certain portion of the file


Quote:
#!/usr/bin/perl

#===========whitelist start=======================
$whitelist = $whitelist . "
test\@yahoo.com
test34\@gmail.com
";
#===========whitelist end=======================


#===========blacklist start=====================
$blacklist = $blacklist . "
test\@gmail.com
test987\@yahoo.com
";
#===================blacklist end===============
I have a file containing above. I need to create 2 variables. 1 variable containing the text inside whitelist start and whitelist end and 1 variable containing the text inside blacklist star and blacklist end. What will happen is variable 1 will have test\@yahoo.com and test34\@gmail.com while variable 2 is test\@gmail.com and test987\@yahoo.com

Is there a way I can do this by making a script.

TIA

Last edited by packets; 06-09-2009 at 08:36 PM.
 
Old 06-09-2009, 10:05 PM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by packets View Post
Is there a way I can do this by making a script.

TIA
yes of course. but what have you tried?
 
Old 06-09-2009, 10:09 PM   #3
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
I'm not really expert in scripting. What I did is I grep all matching "@" which shows list of email address. I just need to output what's inside whitelist start/end only
 
Old 06-09-2009, 10:28 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
its been 4 years since you registered. after that, more than 100++ posts where you learned about sed/awk/Perl/bash etc from people that provide you solutions to your problems. I am sure you have read up a fair amount since then (or have you?). So why don't you try your best. Nobody is an expert on a subject matter without doing something. If you know Perl, use it. Read up docs on how to parse files using Perl.
 
Old 06-09-2009, 11:10 PM   #5
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
thanks for the advise. We'll be reading some more perl books
 
Old 06-09-2009, 11:20 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by packets View Post
thanks for the advise. We'll be reading some more perl books
also do this: perldoc perl or perldoc perltoc on your command line.
 
  


Reply



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
grep file ust Linux - Newbie 4 03-06-2009 04:33 AM
grep for string in file after a certain part of the file B-Boy Programming 6 02-18-2009 07:49 AM
how to use grep and tail to get portion of a file laurasong Linux - General 7 08-19-2007 11:59 PM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
Only load last portion of a file, instead of the whole really big text file 1veedo Linux - General 2 02-20-2006 06:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration