I need help with fgrep or grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I need help with fgrep or grep
# 1  
Old 11-21-2001
Data I need help with fgrep or grep

How can I do an and condition with fgrep.

I want to do:

ps -ef | fgrep -f searchvalues > tempmail.file
mailx -s "Email Subject" email@domain.com < tempmail.file

The search values file contains:
opt/bea.*java.*80
mysqld

What I want is to find things that contain:
mysqld OR
opt/bea AND java AND 80

This doesn't work. Do I have the syntax wrong?

Smilie
# 2  
Old 11-21-2001
I don't think there is a way to use an "AND" expression with fgrep (someone correct me if I'm wrong). You could do something like:

Code:
ps -ef | perl -n -e 'print if (/mysqld/ || (/opt\/bea/ && /java/ && /80/));'

Reading the expressions from a file is another matter, although that wouldn't be too hard.
# 3  
Old 11-21-2001
Try:
ps -ef | grep -E "[m]ysqld|[o]pt/bea.*java.*80"

If you have a grep that doesn't understand -E, then replace "grep -E" with "egrep".
# 4  
Old 11-21-2001
Quote:
Originally posted by Perderabo
Try:
ps -ef | grep -E "[m]ysqld|[o]pt/bea.*java.*80"

If you have a grep that doesn't understand -E, then replace "grep -E" with "egrep".
THANKS!! Both of these worked! I used egrep. Would you mind explaining why I need to use the []?

I would ask if you explain the perl but I think it's over my head!
Smilie

I am not worthy!
# 5  
Old 11-21-2001
Quote:
Originally posted by jimmy
Would you mind explaining why I need to use the []?
[o] is a character class with just a single character. It will match o but it will not match the string "[o]".

This stops the grep command from finding itself. Take out those brackets and the results expand by one with the extra line being the grep process.
# 6  
Old 11-21-2001
Quote:
Originally posted by Perderabo


[o] is a character class with just a single character. It will match o but it will not match the string "[o]".

This stops the grep command from finding itself. Take out those brackets and the results expand by one with the extra line being the grep process.
The results with the [] and without seem the exact same. I guess I don't get it. Either way, IT WORKS!!

THANKS A BUNCH!!



bash-2.03$ ps -ef | egrep "mysqld|opt/bea.*java.*80"
root 3930 1 0 09:53:58 ? 0:44 /opt/bea/jdk131/bin/../bin/sparc/
native_threads/java -server -Dui.root=80 -ms89
root 1015 1 0 11:44:00 ? 1:13 /opt/bea/jdk131/bin/../bin/sparc/
native_threads/java -hotspot -Drib.root=8000 -
root 1161 1 0 11:53:09 ? 0:00 /bin/sh /usr/local/bin/safe_mysql
d --datadir=/cache --pid-file=/cache/transserv
root 1180 1161 0 11:53:09 ? 0:16 /usr/local/libexec/mysqld --based
ir=/usr/local --datadir=/cache --user=root --p

bash-2.03$ ps -ef | egrep "[m]ysqld|[o]pt/bea.*java.*80"
root 3930 1 0 09:53:58 ? 0:44 /opt/bea/jdk131/bin/../bin/sparc/
native_threads/java -server -Dui.root=80 -ms89
root 1015 1 0 11:44:00 ? 1:13 /opt/bea/jdk131/bin/../bin/sparc/
native_threads/java -hotspot -Drib.root=8000 -
root 1161 1 0 11:53:09 ? 0:00 /bin/sh /usr/local/bin/safe_mysql
d --datadir=/cache --pid-file=/cache/transserv
root 1180 1161 0 11:53:09 ? 0:16 /usr/local/libexec/mysqld --based
ir=/usr/local --datadir=/cache --user=root --p
# 7  
Old 11-21-2001
On HP-UX 11.00, it is inconsistent that grep will find itself. First it will, then run the same command again and it will not. So you are better off with the brackets. For example, in the following, you will see that the grep command lists itself:

ps -ef|grep telnetd
root 9076 1005 0 09:16:05 pts/tk 0:00 telnetd
apptest 15532 5588 1 11:04:35 pts/tf 0:00 grep telnetd
root 11008 1005 0 09:55:49 pts/tl 0:00 telnetd

But if you do:

ps -ef|grep [t]elnetd

then it would not.
Jimbo
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Fgrep -v

Using the fgrep command with the -v option. I have two files: file1: dog 1 cat 3 bird 5 fish 7file2: dog catUsing fgrep -v file2 file1 According to the fgrep man page, the output should be bird5 fish 7 but I can't seem to get it to work. Any help would be appreciated. (2 Replies)
Discussion started by: jimmyf
2 Replies

2. Shell Programming and Scripting

Fgrep/grep -f and literal strings

I have a file like this: cat file name = server jobname = 1010 snapshot_name = funky_Win2k12_20140213210409 I'm trying to use grep to isolate that first line (name = server), but grep -f "name = " file as well as fgrep "name = " file returns all 3 lines. How do I return... (1 Reply)
Discussion started by: ampsys
1 Replies

3. Shell Programming and Scripting

Pipe and fgrep

Hi , Please help me resolve the below issue. I need to combine the below two command into one. grep 'ImanItemP' import.report| tr -s ' ' | cut -f2 -d ' ' > tmp.txt fgrep -v -f tmp.txt input.txt > reuired file.txt Thanks Ramesh (4 Replies)
Discussion started by: ramesh12621
4 Replies

4. Shell Programming and Scripting

grep/fgrep/egrep for a very large matrix

All, I have a problem with grep/fgrep/egrep. Basically I am building a 200 times 200 correlation matrix. The entries of this matrix need to be retrieved from another very large matrix (~100G). I tried to use the grep/fgrep/egrep to locate each entry and put them into one file. It looks very... (1 Reply)
Discussion started by: realwindfly
1 Replies

5. Shell Programming and Scripting

Fgrep or grep or awk help - scanning for delimiters.

Hi, I'm struggling a little here, so I figured it's time to ask for help. I have a file with a list of several hundred IDs (the hit file- "hitfile.txt"), which is newline delimited, and a much bigger (~500Mb) text file, "FASTA.txt" with several thousand entries, delimited by ">". It's the... (8 Replies)
Discussion started by: Tbox
8 Replies

6. Shell Programming and Scripting

Awk Vs Fgrep

Hi All, I have 2 files new.txt and old.txt cat new.txt sku1|v1|v2|v3 sku2|v11|v22|v33 sku3|v11|v22|v33 cat old.txt sku1|vx1|vx2|vx3 sku2|vx11|vx22|vx33 sku3|v11|v22|v33 The key column in both files are first column itself. I want to get records in... (6 Replies)
Discussion started by: morbid_angel
6 Replies

7. UNIX Desktop Questions & Answers

Difference grep, egrep and fgrep

Hi All, Can anyone please explain me the difference between grep, egrep and fgrep with examples. I am new to unix environment.. Your help is highly appreciated. Regards, ravi (2 Replies)
Discussion started by: ravind27
2 Replies

8. UNIX for Dummies Questions & Answers

FGREP question

Hi, I need fgrep to search all files in the subdirectories in /var/spool/postfix/defer/... How can I issue such a command? (3 Replies)
Discussion started by: mojoman
3 Replies

9. Shell Programming and Scripting

fgrep fails...!?

Hi all, I need to transport a number of files from one server to other. I like to ensure the integrity using file checksum values. The action plan is, 1. create the list of checksum values for all the files using cksum command in source server. 2. Transfer all the files including the file... (5 Replies)
Discussion started by: r_sethu
5 Replies

10. UNIX for Advanced & Expert Users

fgrep

Hi Guys, Can anyone explain why I'm getting error below? when I execute in other server there is no error, what could be the reason. $ fgrep -f timecell.txt ldap_prev.dat wordlist too large $ wc -l timecell.txt ldap_prev.dat 372461 timecell.txt 3722878 ldap_prev.dat Thanks in... (2 Replies)
Discussion started by: krishna
2 Replies
Login or Register to Ask a Question