LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 04-04-2004, 03:59 PM   #1
john8msu
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Rep: Reputation: 0
Question help w/ grep


I cannot figure out how to do a grep for multiple terms. I've tried to use egrep and i've tried tons of grep statements w/ no luck. It should be pretty simple, here's what I'm lookin to do...

+ 0.975287 0 2 cbr 1000 ------- 1000 0.0 1.0 128 249
- 0.975287 0 2 cbr 1000 ------- 1000 0.0 1.0 128 249
r 0.975384 2 0 cbr 1000 ------- 1000 1.1 0.1 120 248
+ 0.979559 1 2 cbr 1000 ------- 1000 1.1 0.1 121 250
h 0.985172 0 2 cbr 1000 ------- 1000 0.0 1.0 129 251
+ 0.986172 0 2 cbr 1000 ------- 1000 0.0 1.0 129 251
- 0.986172 0 2 cbr 1000 ------- 1000 0.0 1.0 129 251
+ 0.990884 1 2 cbr 1000 ------- 1000 1.1 0.1 122 252
h 0.996394 0 2 cbr 1000 ------- 1000 0.0 1.0 130 253
+ 0.997394 0 2 cbr 1000 ------- 1000 0.0 1.0 130 253
- 0.997394 0 2 cbr 1000 ------- 1000 0.0 1.0 130 253
+ 0.997516 1 2 cbr 1000 ------- 1000 1.1 0.1 123 254
r 0.999209 2 1 cbr 1000 ------- 1000 0.0 1.0 130 253

In output like that I only want to show lines that start w/ the "+" and contain "0 2" as the 3rd and 4th field. For example, the first line should be showed in the sample I posted. I would greatly appreciate you to help out this Thanks in advance!
 
Old 04-04-2004, 05:07 PM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
There actually is a fairly easy way to do this - grep, besides accepting single arguments, also accepts regular expressions. Formulate a regexp for what you want to search for, then do grep 'regexp' <filename>. For example, I put your block up there into a file called "test", then did:
Code:
[laura@laptop laura]$ grep '^\+ [0-9]\.[0-9]* 0 2' test 
+ 0.975287 0 2 cbr 1000 ------- 1000 0.0 1.0 128 249
+ 0.986172 0 2 cbr 1000 ------- 1000 0.0 1.0 129 251
+ 0.997394 0 2 cbr 1000 ------- 1000 0.0 1.0 130 253
Here is some more information on grep, and there are countless sites on regexps to help you.

cool,
Laura

Last edited by rose_bud4201; 04-04-2004 at 05:32 PM.
 
Old 04-04-2004, 06:03 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
The problem with a common reg-ex may be the positional
character, even though it's possible to do it ...


I'd suggest using awk instead ;}

Code:
awk -F" " '$1 ~ /^+/ && $3 ~ /0/ && $4 ~ /2/ {  print }' tmp/rubble
+ 0.975287 0 2 cbr 1000 ------- 1000 0.0 1.0 128 249
+ 0.986172 0 2 cbr 1000 ------- 1000 0.0 1.0 129 251
+ 0.997394 0 2 cbr 1000 ------- 1000 0.0 1.0 130 253

Cheers,
Tink
 
Old 04-05-2004, 12:44 AM   #4
john8msu
LQ Newbie
 
Registered: Apr 2004
Posts: 3

Original Poster
Rep: Reputation: 0
thanks a lot, i appreciate it
 
  


Reply



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 ?? can grep us variables? DaFrEQ Linux - Software 4 09-14-2005 12:22 PM
help on grep!!!! sanjith11 Programming 5 01-20-2005 05:43 PM
What does rpm -qa |grep th* (as compared to rpm -qa |grep th) display? davidas Linux - Newbie 2 03-18-2004 01:35 AM
"Undeleting" data using grep, but get "grep: memory exhausted" error SammyK Linux - Software 2 03-13-2004 03:11 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 06:46 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
Open Source Consulting | Domain Registration