Hi,
I have a file with values,
file1:
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 ,
grep BELL-1180-1180-81 file1 | grep -v "101" | grep -v "102"
and
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.
awk -F"|" '$1~/BELL-1180-1180-81/ && $2!~/:10[12]$/' file
1 Like
Thanks it works,
Could you please explain the command ?
1 more question,
Is it i can use a variable here ,
awk -F"|" '$1~/$VAR/ && $2!~/:10[12]$/' file
instead of this ,
awk -F"|" '$1~/BELL-1180-1180-81/ && $2!~/:10[12]$/' file
could you please give me the command ?
rdcwayx
8
grep BELL-1180-1180-81 file1 | grep -v "101|$" | grep -v "102|$"
okstyr
9
awk is cool and worth learning, but this will also work
grep BELL-1180-1180-81 file1 | grep -v ":101|" | grep -v ":102|"
frewise
10
grep BELL-1180-1180-81 file1 | grep -wv 101 | grep -wv 102
-w, --word-regexp
Select only those lines containing matches that form whole words.