hello experts,
I have a file: File1
Sample Test1
This is a Test
Sample Test2
Another Test
Final Test3
A final Test
I can use sed to delete the line with specific text
ie:
sed '/Test2/d' File1.txt > File2.txt
How can I delete the line with the matching text and the line immediately after.
so My resulting file would look like
File2:
Sample Test1
This is a Test
Final Test3
A final Test
thanks
# echo "1\n2\n3\n4\n5\n6" | sed -e '/2/{N;d;}'
1
4
5
6
drl
January 11, 2008, 2:20pm
3
Hi.
Also:
% echo "1\n2\n3\n4\n5\n6" | sed '/2/,+1d'
1
4
5
6
According to man sed:
cheers, drl
Hmmm yes but that didn't work on my sed (AIX). YMMV!!!
drl
January 11, 2008, 3:59pm
5
Hi, gus2000.
The man page for the GNU version did not say that that was an extension. I'll try to see if that's POSIX. The version on FreeBSD 4.1 man page:
and the "+1" syntax also did not work there ... cheers, drl
shell:
#!/bin/sh
f=0
while IFS= read -r line
do
case $line in
*pattern* ) f=1; continue ;;
esac
if [ "$f" -eq 1 ]; then
f=0
continue
else
echo $line
fi
done <"file"
awk:
awk '/pattern/{getline;next}{print}' file
I used the awk suggestion below since I was already using awk for something else...It worked great
thanks