Try using "grep -n -B <lines> <string>". That will give the number of lines before a matching string and the line numbers.
You could then keep the line numbers in an array and then delete each line afterwards.
Hi all,
how can I delete previous n number of lines of matching pattern..
I know how to delete the lines after the matching pattern using sed command
sed -e '/pattern1/,/pattern2/d' filename
but I am searching for deleting previous 3 lines of matching pattern.....
I am doing this because I want to delete all the lease entries matching MAC address....
Please help....
Try using "grep -n -B <lines> <string>". That will give the number of lines before a matching string and the line numbers.
You could then keep the line numbers in an array and then delete each line afterwards.
Thanks!
Now I've gotta find out how to delete lines if we know the line number... probably I have to use sed script... if you know then please let me know how can I do it......
Thanks for your reply...
What is wrong with something simple, like:I am doing this because I want to delete all the lease entries matching MAC address....
Code:egrep -v '(DHCPREQUEST | DHCPACK | DHCPDISCOVER | DHCPOFFER)' -e TH:EM:AC:AD:DR:AS /var/log/messages
Don't worry Ma'am. We're university students, - We know what We're doing.
'Ruiat coelum, fiat voluntas tua.'Datalogi - en livsstil; Intet liv, ingen stil.
Bookmarks