grep out unwanted lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep out unwanted lines
# 1  
Old 03-19-2010
grep out unwanted lines

Hi,

I got a log file and I want to grep out a list of unwanted line which are IP's.

Basiclly I want everything ecxept the ip's from my list.
If I do a

Code:
while read line
do
  grep -v $ip_from_my_list logfile
done <ip_list

it just grep's one IP at a time and repeats. Smilie

Thanks for any help.

Last edited by Franklin52; 03-19-2010 at 07:12 AM.. Reason: Please indent your code and use code tags!
# 2  
Old 03-19-2010
Code:
grep -v -f ip_list logfile

# 3  
Old 03-19-2010
What you are looking for is the "-f <file>" option of grep. Have a careful look into the neverending tome of Unix knowledge (for mere mortals: issue "man grep") and investigate how you could provide grep with a list of patterns from a file.

I hope this helps.

bakunin
# 4  
Old 03-19-2010
Thanks worked never used -f before Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk prints unwanted new lines

Hello, I need a little help with the following: I'm using AWK to read input from a comma-seperated value file, and only printing certain fields like so: awk -F "," '{print $1,$3,$6}' /list.csv | tail -1 Which outputs the following: server1 APPID OS I run into a problem... (8 Replies)
Discussion started by: LinuxRacr
8 Replies

2. Shell Programming and Scripting

get rid of unwanted lines

Hi , My output contains the below contents When i execute df -h | grep / | grep -v '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' i get output as below tpshghghg.fgh.com:/vol/scmvol1/scm-vobstore/WebArch.vbs 1.7T 1.3T 452G 74% /vob/WebArch... (6 Replies)
Discussion started by: ptappeta
6 Replies

3. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

4. Shell Programming and Scripting

AWK/GREP: grep only lines starting with integer

I have an input file 12.4 1.72849432773174e+01 -7.74784188610632e+01 12.5 9.59432114416327e-01 -7.87018212757537e+01 15.6 5.20139995965960e-01 -5.61612429666624e+01 29.3 3.76696387248366e+00 -7.42896194101892e+01 32.1 1.86899877018077e+01 -7.56508762501408e+01 35 6.98857157014640e+00... (2 Replies)
Discussion started by: chrisjorg
2 Replies

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

6. Shell Programming and Scripting

Print lines between two lines after grep for a text string

I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like: <ROW> some information more information </ROW> I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies

7. Shell Programming and Scripting

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

8. Shell Programming and Scripting

Remove unwanted lines

I have a .xml file, where i need some output. The xml file is like: Code: <?******?></ddddd><sssss>234</dfdffsdf><sdhjh>534</dfdfa>......... /Code I need the output like: code 234 534 . . . /code How can i do it? (5 Replies)
Discussion started by: anupdas
5 Replies

9. UNIX for Advanced & Expert Users

How to Remove the unwanted Blank Lines

I have a file with the below data, i would like to remove the end blank lines with no data. I used the below commands but could not able to succeed, could you please shed some light. Commands Used: sed '/^$/d' input.txt > output.txt grep -v '^$' input.txt > output.txt input.txt file... (5 Replies)
Discussion started by: Ariean
5 Replies

10. Shell Programming and Scripting

Filter unwanted lines

Hi All, I have the below input and i only want to filter out some un-wanted info from here. Expected output is below. Can somebody help ? The catch is that i want to grep those lines with term "k=" and lines with term "**" as the 1st column and "07" as the last column. And the number of... (15 Replies)
Discussion started by: Raynon
15 Replies
Login or Register to Ask a Question