Dear All
I want to search string "1000" from input file and if it found i want remove line that contain 1000 and also remove 3 line above it and 2 line below it.
INPUT FILE:
BHAT-D 2
aaa
ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES
50 1000 3 0 HEX 1 1
bbb
TEXT PAGE
output:
blank file.
kindly let me knw possible ways.
regards
jaydeep
are the "1000" string exist in a file that paragraph separated ??
which one of the cases your file look like case1 or case2???
case 1:
BHAT-D 2
aaa
ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES
50 1000 3 0 HEX 1 1
bbb
TEXT PAGE
hhhhh
FFFF DDDD YYYY JJJJ KKK
30 90 8888 6666
nnnnn
TOTO NONO
case 2:-
BHAT-D 2
aaa
ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES
50 1000 3 0 HEX 1 1
bbb
TEXT PAGE
hhhhh
FFFF DDDD YYYY JJJJ KKK
30 90 8888 6666
nnnnn
TOTO NONO
$ cat test
asdfasdf
asdfds
est blubb
dfgtra
sdf
blubb weafsadf
$ sed '/blubb/d' test
asdfasdf
asdfds
dfgtra
sdf
Edit: ok sry, should read the whole text ^^
here with grep, but options -A and -B are not available on every os
1
2
asdfasdf
asdfds
est blubb
3
dfgtra
sdf
4
5
grep -v "$(grep -A 2 -B 3 blubb test)" test
1
sdf
4
5
Edit2: but theres a problem with this one,
if your file is paragraph separated:
use below perl code..
perl -00 -wnl -e '! /1000/ and print;' infile.txt
:):)
my input is metion below:
file is space and line seperated. not paragraph.
input file:
BHAT-D 2
aaa
ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES
50 1000 3 0 HEX 1 1
bbb
TEXT PAGE
BHAT-b 2
aaa
ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES
50 10 3 0 HEX 1 1
bbb
TEXT PAGE
output file:
BHAT-b 2
aaa
ID CODE GS UPDATE MODE LANG MCO MCL NUMPAGES
50 10 3 0 HEX 1 1
bbb
TEXT PAGE
that mean line contain 1000 and 3 line above it and 2 below it must be remove.
anbu23
February 3, 2010, 10:39am
6
awk -v RS="" -v ORS="\n\n" ' $0 !~ "1000" ' file
this will work indeed
perl -00 -wnl -e '! /1000/ and print;' infile.txt
:D:D:D
this will only work with AIX-grep
grep -vp 1000 yourfile