?
Solved

perl script to extract lines.

Posted on 2007-10-08
3
Medium Priority
?
705 Views
Last Modified: 2008-01-09
File test.csv in following format

cool dude!
be frank
"jumbo jet","A370"
airbus,from,UK
Boeing,from,US
"fly","with"
whatsup
c ya

Please suggest Perl script to extract lines between"jumbo jet","A370" and "fly","with" and output to file called output.csv
output.csv should be as given below.

airbus,from,UK
Boeing,from,US
0
Comment
Question by:Begunix
3 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 1400 total points
ID: 20038587
perl -ne 'print if (/jumbo jet","A370"/../"fly","with"/)=~/^([2-9]|\d{2,})$/' test.csv  >  output.csv
0
 

Author Comment

by:Begunix
ID: 20043051
Thanks for the reply.
But instead of one liner code, how to achieve the desired result by reading the file.
open(TXT,"text.csv)
while(<TXT>)
{
...

}

Thanks
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 600 total points
ID: 20044306
converting ozo's code into a non-one-liner...


open(TXT,"<test.csv") or die "input: $!\n";
while(<TXT>) {
      print if (/jumbo jet","A370"/../"fly","with"/)=~/^([2-9]|\d{2,})$/;
}
close(TXT);
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question