Remove a specific line from grep output string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove a specific line from grep output string
# 1  
Old 02-03-2010
Remove a specific line from grep output string

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
# 2  
Old 02-03-2010
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:

Code:
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:-

Code:
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

# 3  
Old 02-03-2010
Code:
$ cat test
asdfasdf
asdfds
est blubb

dfgtra
sdf
blubb weafsadf

Code:
$ 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

Code:
1
2
asdfasdf
asdfds
est blubb
3
dfgtra
sdf
4
5

Code:
grep -v "$(grep -A 2 -B 3 blubb test)" test
1
sdf
4
5

Edit2: but theres a problem with this one,

Last edited by funksen; 02-03-2010 at 11:04 AM..
# 4  
Old 02-03-2010
if your file is paragraph separated:

use below perl code..

Code:
perl -00 -wnl -e '! /1000/ and print;' infile.txt

SmilieSmilieSmilie
# 5  
Old 02-03-2010
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.
# 6  
Old 02-03-2010
Code:
awk -v RS="" -v ORS="\n\n" ' $0 !~ "1000" ' file

# 7  
Old 02-04-2010
this will work indeed

Code:
perl -00 -wnl -e '! /1000/ and print;' infile.txt

SmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep string in a file and paste next line in a specific way

Hello, I know there are many questions and replies regarding grep command. What I would like to do is a bit different. File A: hello world welcome to my page this is my test site how are you I am fine, thank you where have you been I was in hospital really hope you are fine now Thanks,... (10 Replies)
Discussion started by: baris35
10 Replies

2. Shell Programming and Scripting

Remove duplicate consecutive lines with specific string

Hello, I'm trying to remove the duplicate consecutive lines with specific string "WARNING". File.txt abc; WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 WARNING 2345 bcd; abc; 123 123 123 WARNING 1234 WARNING 2345 WARNING 2345 efgh; (6 Replies)
Discussion started by: Mannu2525
6 Replies

3. Shell Programming and Scripting

Remove every line with specific string, and also the one above and below it

I would like to identify every line with a specific string, in this case: "Mamma". I would like to remove that line, and also the line above it and below it. So the below Where are all amazing Flats Look At The Great Big White Hey There Hot Mamma You Are So hot Baby I wish You were Mine... (5 Replies)
Discussion started by: phpchick
5 Replies

4. UNIX for Dummies Questions & Answers

Grep contains specific string

i have file input dsgfdgdfgd> cab |egrep -i '(active|cbu)' 130502-11:34:11 10.133.1.153 9.0j stopfile=/tmp/15959 Trying password from ipdatabase file: /opt/ericsson/amos/moshell/sitefiles/ipdatabase... .. 0 1 CBU1 OFF ON 16HZ ROJ1192209/1 R5E TU8BZ04466... (3 Replies)
Discussion started by: radius
3 Replies

5. Shell Programming and Scripting

grep the output between specific lines

Symmetrix ID : 00000001234 Host Name : myown Identifiers Found : 5000000000000000 5000000000000001 Device Cap(MB) Attr Dir:P ------ ------- ---- ---- 1234 25886 (M) 8D:1, 9D:1 0123 25886 (M) 8D:1, 9D:1 1345 25886 (M) ... (5 Replies)
Discussion started by: maddy.san
5 Replies

6. UNIX for Dummies Questions & Answers

How to remove a string from a specific column in a file

Hello, A basic query. How can I remove a string from a specific column. For example, remove "abcd" just from column 2 in example file: abcd abcd1 abcd abcd2 abcd abcd3 to get output: abcd 1 abcd 2 abcd 3 Thank you!:) (4 Replies)
Discussion started by: auburn
4 Replies

7. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies

8. UNIX for Dummies Questions & Answers

How to remove columns with specific string?

If I have a data test.txt with 1000 columns such as: id sex gene1 gene2 gene2.dl gene3 gene4 gene4.dl ....... 1 1 AA AT AT TT AT AT ....... 2 1 AG TT TT TA AA AA ....... 3 2 AA AT AT TT AT ... (2 Replies)
Discussion started by: AMBER
2 Replies

9. Shell Programming and Scripting

Remove Line that contains specific string

I am looking for a way to remove any line in a text file that contains the string "Mac address". I guess you would grep and sed, but I am not sure how to do this. Thanks for you help. (3 Replies)
Discussion started by: CBarraford
3 Replies
Login or Register to Ask a Question