LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-14-2003, 07:37 AM   #1
lleemon
LQ Newbie
 
Registered: Jun 2003
Location: Minnesota
Posts: 5

Rep: Reputation: 0
grep -v issue (RESOLVED)


I am writting a script to display only certain log files but I can't get the following to work:

PHP Code:

#IPs  are made up
vgrepstr="grep -v 11.11.11.11 | grep -v 11.11.11.12 | grep -v 1.1.1.1"

filelist="access_log.4 access_log.3 access_log.2 access_log.1 access_log"

  
#for each access_log file look for site given and pull IP's out
  
for curfile in $filelist
  
do
      
cat $curfile grep $v_site |  $vgrepstr awk -F" " '{print $1}'
  
done 
My issue is the $vgrepstr. For some reason the pipe (|) isn't recognized. Any way I can get it to read as a pipe?

Thanks in advance

Last edited by lleemon; 06-16-2003 at 03:50 PM.
 
Old 06-14-2003, 09:41 AM   #2
Azmeen
Senior Member
 
Registered: May 2003
Location: Malaysia
Distribution: Slackware, LFS, CentOS
Posts: 1,307

Rep: Reputation: 46
Try escaping it with a backslash... eg.:
Code:
vgrepstr="grep -v 11.11.11.11 \| grep -v 11.11.11.12 \| grep -v 1.1.1.1"
 
Old 06-14-2003, 10:15 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
i'd recommend a better use of grep, e.g using regexes rather than three seperate processes:

grep -v 11.11.11.1[12] $curfile

i'd assume that those ip's your using are ficticious though...
 
Old 06-14-2003, 10:41 AM   #4
lleemon
LQ Newbie
 
Registered: Jun 2003
Location: Minnesota
Posts: 5

Original Poster
Rep: Reputation: 0
Neither of these work for me.

when I do a bash -x scriptname.sh
it gets to the grep and what is displayed is:

+ cat /home/virtual.....
+ grep http://www.........
+ grep -v 11.11.11.11 '\|' grep -v 11.11.11.12 '\|' grep -v 1.1.1.1
grep: \|: No such file or directory
grep: grep: No such file or directory
grep: 11.11.11.12: No such file or directory
grep: \|: No such file or directory
grep: grep: No such file or directory
grep: 1.1.1.1: No such file or directory

Same response for the [12]
grep: [12]: No such file or directory
grep: grep: No such file or directory
grep: 11.11.11.12: No such file or directory
grep: [12]: No such file or directory
grep: grep: No such file or directory
grep: 1.1.1.1: No such file or directory

Looks like the first grep -v is working but all the rest are not due to the ' ' around the |, \|, and [12] that I have tried.
 
Old 06-14-2003, 12:14 PM   #5
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 49
Before I start digging into this too deeply, what, exactly are you attempting to do? What is the one field you are using awk to get?
 
Old 06-14-2003, 01:11 PM   #6
lleemon
LQ Newbie
 
Registered: Jun 2003
Location: Minnesota
Posts: 5

Original Poster
Rep: Reputation: 0
Good question. The reason for doing this is that I have many scripts created already that we view results (from our logs) and we don't want our IP's to show up in these results. Each of these scripts has the following in them:
IP1="ipaddresshere"
IP2="ipaddresshere"
.... plus many more ....

then I later do:
cat logfile | grep -v IP1 | grep -v IP2 | .. and all other ip's ....

Since our IP's change it gets really messy to go into each script and add the new ip to the list and the cat portion. So far I got it so I can create a text file with just the ip's and then all the scripts would read this central file and create the grep -v IP's dynamically so I never have to up date the scripts, at least for new/updated IP changes. My only issue is that in the string portion it doesn't work properly.

Hope this makes sense.
 
Old 06-14-2003, 09:15 PM   #7
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 49
So, you have a bunch of log files that report stuff with IP addresses, and you want to cull out everything that contains the IP addresses of your computers, all of which have dynamic IP addresses? I guess my understanding of what you want isn't complete, but to get what you show at the top, do the following:

Code:
vgrepstr="11.11.11.11|11.11.11.12|1.1.1.1"

for $curfile in $filelist 
do
  grep $v_site $curfile |  grep -v -E $vgrepstr
done
The -E tells grep to treat the next expression as a complex regex, and the | in the $vgrepstr can be thought of as a binary "OR".

Last edited by moses; 06-14-2003 at 09:18 PM.
 
Old 06-16-2003, 03:50 PM   #8
lleemon
LQ Newbie
 
Registered: Jun 2003
Location: Minnesota
Posts: 5

Original Poster
Rep: Reputation: 0
Yep, works perfectly!

Thanks for all the help all that posted.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Grep parsing issue selfsck Linux - General 3 07-11-2004 08:38 PM
grep issue of escaping backticks in perl rajatgarg Programming 2 05-27-2004 01:27 AM
Shell grep issue philipz Programming 8 05-05-2004 01:50 PM
"grep: /etc/issue: No such file or directory" hunter_one Linux - Software 6 10-15-2003 03:27 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 11:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration