grep/sed to remove lines in file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep/sed to remove lines in file
# 1  
Old 01-11-2011
grep/sed to remove lines in file

Hi,

I have a file with values,
file1:
Code:
BELL-1180-1180-81|577:1017|
BELL-1180-1180-81|jm10i-auto-stub1/577:102|
BELL-1180-1180-81|jm10i-auto-stub1/577:101|
BELL-1180-1180-81|jm10i-auto-stub1/577:1700|
BELL-1180-1180-81|jm10i-auto-stub1/577:1699|

I need to remove the lines which has "101" and "102"

I tried ,
Code:
grep BELL-1180-1180-81 file1 | grep -v "101" | grep -v "102"

and
Code:
grep BELL-1180-1180-81 file1 | sed '/101/d' | sed '/102/d'

but i see the entry with "1017" is also getting removed and i want to retain the entry with "1017"

Plz help me.

Last edited by Scott; 01-14-2011 at 06:28 PM.. Reason: Code tags, please...
# 2  
Old 01-12-2011
Code:
 awk -F"|" '$1~/BELL-1180-1180-81/ && $2!~/:10[12]$/' file

This User Gave Thanks to JavaHater For This Post:
# 3  
Old 01-12-2011
Thanks it works,

Could you please explain the command ?
# 4  
Old 01-12-2011
# 5  
Old 01-12-2011
1 more question,

Is it i can use a variable here ,
Code:
awk -F"|" '$1~/$VAR/ && $2!~/:10[12]$/' file

instead of this ,
Code:
awk -F"|" '$1~/BELL-1180-1180-81/ && $2!~/:10[12]$/' file


Last edited by Scott; 01-14-2011 at 06:28 PM.. Reason: Code tags
# 6  
Old 01-12-2011
# 7  
Old 01-12-2011
could you please give me the command ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove repetitive lines in a file with sed?

Hello, My goal is the make all x times repeated lines into a single line. I need to attain the expected output with sed -i , I need to overwrite the MyFile MyFile: Hello World Welcome Hello World Welcome Back This is my test Expected output: Hello World Welcome Welcome Back This is... (6 Replies)
Discussion started by: baris35
6 Replies

2. Shell Programming and Scripting

sed to remove all lines in file that are not .vcf.gz extention

I am trying to use sed to remove all lines in a file that are nor vcf.gz. The sed below runs but returns all the files with vcf.gz in them, rather then just the ones that end in only that extention. Thank you :). file ... (9 Replies)
Discussion started by: cmccabe
9 Replies

3. Shell Programming and Scripting

Using sed in a loop/to remove lines contained in variable from file

I've tried numerous commands, but I am not sure how to use sed in a loop. This is what I have: VARZ contains CARD_FILE_LIST and it also contains CARD_FILE_LIST2 so echo "$VARZ" CARD_FILE_LIST CARD_FILE_LIST2 I have a file with 60 lines in /tmp/testfile it and I want those lines deleted... (3 Replies)
Discussion started by: newbie2010
3 Replies

4. Shell Programming and Scripting

How to remove certain lines using sed?

Hi, I am new to unix and i started some scripting recently. Please go through the following script i wrote. #!/bin/sh file='path../tfile' file1='path../tfile1' rmfile='path../test2' C1=1 C2=1 exec 3< $file1 while read LINE1; do read LINE2 <&3 a=$LINE1 b=`expr $LINE2 - 1` ... (1 Reply)
Discussion started by: Subbu123
1 Replies

5. UNIX for Dummies Questions & Answers

How to remove certain lines using sed?

Hi I have the following kind of line sin my file . print ' this is first'. print ' this is firs and next ' ' line continuous '. -- this is entire print line. print ' this is first and next ' ' line continuous and' 'still there now over'. -- this 3lines together a single print line. ... (5 Replies)
Discussion started by: Sivajee
5 Replies

6. Shell Programming and Scripting

Remove a range of lines from a file using sed

Hi I am having some issue editing a file in sed. What I want to do is, in a loop pass a variable to a sed command. Sed should then search a file for a line that matches that variable, then remove all lines below until it reaches a line starting with a constant. I have managed to write a... (14 Replies)
Discussion started by: Andy82
14 Replies

7. UNIX for Dummies Questions & Answers

Using grep to remove cells instead of whole lines

I would like to use grep to remove certain strings from a text file but I can't use the grep -v option because it removes the whole line that includes the string whereas I just want to remove the string. How do I go about doing that? My input file: Magmas CEU rs12542019 CPNE1 RBM12 CEU... (2 Replies)
Discussion started by: evelibertine
2 Replies

8. UNIX Desktop Questions & Answers

Using grep to remove cells instead of lines

I would like to use grep to remove certain strings from a text file but I can't use the grep -v option because it removes the whole line that includes the string whereas I just want to remove the string. How do I go about doing that? My input file: Magmas CEU rs12542019 CPNE1 RBM12 CEU... (1 Reply)
Discussion started by: evelibertine
1 Replies

9. UNIX for Dummies Questions & Answers

Grep command to remove blank lines

The following grep command grep -v "^$" filename > newfilename does not populate the new file with any data. I see it search the entire input file but the output file never gets filled. Is this not the correct command for what Im looking to do? (2 Replies)
Discussion started by: aispg8
2 Replies

10. Shell Programming and Scripting

using sed to remove lines

Can somebody explain why my sed command is not working. I do the folloinwg: Generates a binary file to /tmp/x1.out /usr/lib/sa/sa2 -s 4:00 -e 8:00 -i 3600 -A -o /tmp/x1.out decodes the file (no problem so far) sar -f /tmp/x1.out When I do this it does not appear to delete the... (4 Replies)
Discussion started by: BeefStu
4 Replies
Login or Register to Ask a Question