Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-05-2009
VIP Member
 

Join Date: Nov 2008
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 12-05-2009
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 6,777
Thanks: 2
Thanked 68 Times in 63 Posts
Can you not use grep

Code:
grep 'APPLE' infile > outfile

Or is this a classroom assignment?
  #3  
Old 12-05-2009
gaurav1086's Avatar
Registered User
 

Join Date: Nov 2009
Location: india
Posts: 277
Thanks: 1
Thanked 2 Times in 2 Posts
hi..
#perl -wln -e 'print if /\bAPPLE\b/' your_file > new_file
  #4  
Old 12-06-2009
Registered User
 

Join Date: May 2008
Location: Chennai
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts

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  
Old 12-06-2009
scottn's Avatar
scottn scottn is online now Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 2,924
Thanks: 26
Thanked 146 Times in 136 Posts
Quote:
Originally Posted by tene View Post
How to use code tags?
Is that a feature of this website?
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  
Old 12-06-2009
Registered User
 

Join Date: May 2008
Location: Chennai
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
cout<<"Thank you. I will follow it from next time.";

btw, my edit controls are inactive.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:38 AM.