help with onliner


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with onliner
# 1  
Old 01-31-2008
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
# 2  
Old 01-31-2008
something like this

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

Login or Register to Ask a Question

Previous Thread | Next Thread

1 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl onliner to search the last line with an occurence of a pattern

Hi I need a perl onliner which seaches a line starting with a pattern(last occurence) and display it. similar to grep 'pattern' filename | tail -1 in UNIX Ex: I want to display the line starting with "cool" and which is a last occurence adadfadafadf adfadadf cool dfadfadfadfara... (4 Replies)
Discussion started by: ammu
4 Replies
Login or Register to Ask a Question