The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing last character from each line of file cjhancock Shell Programming and Scripting 17 08-29-2008 01:05 AM
removing particular lines ending with a .cnt extension in a text file ramky79 SUN Solaris 2 03-03-2008 02:17 AM
Removing a particular line from a text file sendhilmani123 Shell Programming and Scripting 5 05-31-2006 05:32 AM
Removing lines in a text file. WABonnett Shell Programming and Scripting 4 11-25-2003 08:27 AM
removing commas from text file hcclnoodles UNIX for Dummies Questions & Answers 6 03-26-2003 01:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 02-12-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by outthere_3 View Post
open(F, "<file") or die "cannot open file:$!\n";
while ( <F> ) {
if ( /nul/ ) {
@a = split(/nul/);
print $a[0] . "]\n";
}
}
close(F);

can you please explain this line by line for me.
open and while loop : perldoc perlopentut
split : perldoc -f split
Reply With Quote
Forum Sponsor
  #9  
Old 02-12-2008
agn agn is offline
Registered User
 

Join Date: Feb 2008
Posts: 97
Same thing can be achieved by

Code:
sed 's/\(.*\) nul.*/\1]/' inuput_file
Reply With Quote
  #10  
Old 02-12-2008
Registered User
 

Join Date: Jan 2008
Posts: 328
Quote:
Originally Posted by ghostdog74 View Post
don't have to use regular expression. Unless i read your requirement wrong,
Code:
open(F, "<file") or die "cannot open file:$!\n";
while ( <F> ) {
 if ( /nul/ ) {
  @a = split(/nul/);
  print $a[0] . "]\n";
 } 
}
close(F);
output:
Code:
# ./test.pl
[na *oparea* check 0 ]
But you are using a regexp (2 of them), just a much simpler one. If that works, is a nice lean solution.
Reply With Quote
  #11  
Old 02-13-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by KevinADC View Post
But you are using a regexp (2 of them), just a much simpler one. If that works, is a nice lean solution.
yes, i should've said, "don't have to use too much regular expression". generally, the if the operation is not too complex, simple regex or string functions will suffice.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
awk, perl script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0