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 directory in an input file chrysSty UNIX for Dummies Questions & Answers 2 06-04-2008 08:12 PM
Removing text from a line in a file outthere_3 Shell Programming and Scripting 10 02-13-2008 12:38 AM
Removing a particular line from a text file sendhilmani123 Shell Programming and Scripting 5 05-31-2006 05:32 AM
sed not outputting last line of input file 2reperry Shell Programming and Scripting 3 12-16-2005 09:51 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2005
Registered User
 

Join Date: May 2005
Posts: 27
perl question - removing line from input file

In perl I want to do remove the top line of my input file then process the next line. I want to do something like
head -1 inputfile > temp
grep -v temp inputfile > newinputfile
cp newinputfile inputfle

is this possible in perl?
Reply With Quote
Forum Sponsor
  #2  
Old 05-23-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Why not just use sed?

sed '1d' my_file > new_file && mv new_file my_file

Or - look at this.

Cheers
ZB
Reply With Quote
  #3  
Old 05-23-2005
Registered User
 

Join Date: May 2005
Posts: 27
I will give these methods a try. Thanks
Reply With Quote
  #4  
Old 06-07-2005
Registered User
 

Join Date: May 2005
Posts: 27
zazzybob,

perl -pi -e '$_ = "" if ( $. == 1 );' large_file
I am trying to convert the above perl command line you reference to a script.
I am not sure what the -pi does for the command line. But what I have below works but I am wondering if it is efficent or should be done in another manner.

$ cat junk
#!/usr/bin/perl

open (infile, "+< /adsm/ACTIVITIES/CHANGES/TGA2_OBSOLETE_CLNUP/x ");
open (outfile,">/adsm/ACTIVITIES/CHANGES/TGA2_OBSOLETE_CLNUP/z");
while ( $line = <infile>) {
if ($. == 1) {
}
else {
print (outfile "$line");
}
} #end while
system ("cp /adsm/ACTIVITIES/CHANGES/TGA2_OBSOLETE_CLNUP/z /adsm/ACTIVITIES/CHANGES/TGA2_OBSOLETE_CLNUP/x");
close(infile);
close(outfile);
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:16 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