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
Perl onliner to search the last line with an occurence of a pattern ammu Shell Programming and Scripting 4 01-30-2008 09:09 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Apr 2007
Posts: 10
help with onliner

Hi

I want to insert a line after a line by searching for the last occurence for that. I have taken an already posted example.
Say in the following file

a.txt
------
adadfadafadf
adfadadf
cool dfadfadfadfara
adfadfadf
cool aaaaaaaaaaaaaa
hai how are you

I want to insert after the red line. With unix sed command we can do it, but i think it needs an temp file. Using Perl we can do it with out using temp file. Perl onliner perl -i -ne 'print ..................' file name will help.
Can some give me the exact command

Thanks in advance
Lijju Math
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-31-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,454
something like this

Code:
perl -e 'while(<>) { if ( /cool aaa/ ) { print $_."this is the line\n"; } else { print } }' filename
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:15 AM.


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

Content Relevant URLs by vBSEO 3.2.0