I have my data something like this. I want to delete all the lines before the frist instance of the key word 'ravi kumar'
aaa
bbbbbb cccccc
ddddd eeeee
1234 ravi kumar
aaaaaa vvvvvvv
5678 ravi kumar
rrrrrrr mmmmmmm
I want the output as follows.
1234 ravi kumar
aaaaaa vvvvvvv
5678 ravi kumar
rrrrrrr mmmmmmm
Please help me.
awk '/ravi kumar/,/*/ {print $0}' yourfle
How about this?
sed -n '/ravi kumar/,/*/p' file
Sed is working perfectly where as there seems to be a syntax issue with awk command above.
Thanks a lot for your help.
aigles
5
sed -n '/ravi kumar/,$p' file
awk '/ravi kumar/,i++' file
Jean-Pierre.
Jean-Pierre,
Your awk command ignores the last line.
Another approach with awk:
awk '/ravi kumar/{p=1}p' file
Regards
aigles
7
Oups! you're right Franklin.
awk '/ravi kumar/,p' file
Input:
aaa
bbbbbb cccccc
ddddd eeeee
1234 ravi kumar
aaaaaa vvvvvvv
bbbbbbb wwwwwwww
ccccccccc zzzzzzzzzz
5678 ravi kumar
rrrrrrr mmmmmmm END
Output:
1234 ravi kumar
aaaaaa vvvvvvv
bbbbbbb wwwwwwww
ccccccccc zzzzzzzzzz
5678 ravi kumar
rrrrrrr mmmmmmm END
Jean-Pierre.
Thanks a lot for your inputs. Similarly, how can i delete the lines after the last occurence of the keyword?
Bumping up posts or double posting is not permitted in these forums.
Please read the rules, which you agreed to when you registered, if you have not already done so.
Proceed here:
http://www.unix.com/shell-programming-scripting/115621-delete-lines-after-last-instance-keyword.html\#post302338987
Thank You.
The UNIX and Linux Forums.