|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Perl : Find a string and Print full line
Hi
Need a perl script to read lines in a file, scan for a string named "APPLE" and write to different file the only lines containing the matched string. |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
Can you not use grep Code:
grep 'APPLE' infile > outfile Or is this a classroom assignment? |
|
#3
|
||||
|
||||
|
hi..
#perl -wln -e 'print if /\bAPPLE\b/' your_file > new_file |
|
#4
|
|||
|
|||
|
Code:
open(IN,"<inputFile");
open(OUT,">outputFile");
while(<IN>)
{
chomp;
if( $_ =~ m/APPLE/ )
print OUT $_;
}---------- Post updated at 10:22 PM ---------- Previous update was at 01:31 PM ---------- How to use code tags? Is that a feature of this website? Last edited by Franklin52; 12-06-2009 at 07:05 AM.. Reason: Please use code tags! |
|
#5
|
||||
|
||||
|
It's a feature of many forum sites.
You can either type it in yourself: [ code] <-- without the space .... [/code] Or you can click the # icon in the edit window, near the end of the line with B I U etc.. |
|
#6
|
|||
|
|||
|
Code:
cout<<"Thank you. I will follow it from next time."; btw, my edit controls are inactive. |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Perl Script - Print Content of next line | zarahel | Shell Programming and Scripting | 6 | 10-20-2009 03:10 PM |
| Grep a string and print a string from the line below it | kingpeejay | Shell Programming and Scripting | 4 | 06-23-2009 12:26 PM |
| [Perl] Find one string, change another string. | ejdv | Shell Programming and Scripting | 5 | 06-10-2009 03:44 AM |
| AWK...find a string ,if so print it | hegdeshashi | UNIX for Dummies Questions & Answers | 1 | 06-01-2009 04:34 PM |
| Unix find command to print directory and search string | princein | UNIX for Dummies Questions & Answers | 4 | 03-06-2007 07:46 AM |