GREP issues


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers GREP issues
# 1  
Old 05-20-2005
GREP issues

Hi all,
I am trying to perform a simple task with grep, this is what I execute:

grep -i -n 'error|fail|warning' cl_less.out

when I execute it it does not give any errors, as in the command worked and back to the command prompt, but if I run each grep independently the I do get a real fail:

grep -i -n error cl_less.out
161726:ERROR at line 1:

715509:ERROR:
715510:ORA-00604: error occurred at recursive SQL level 1
715525:ERROR at line 1:
715556:ERROR:
715557:ORA-00604: error occurred at recursive SQL level 1
715592:ERROR at line 1:
715605:ERROR:
715606:ORA-00604: error occurred at recursive SQL level 1
806844:ERROR at line 1:

What am I doing wrong with first command that it does not print the error.

also what do I need to add the first command to change directory and do grep at the same time, also I want to grep with that command for several files with different names at the same time.

Your help is much appreciated.
# 2  
Old 05-20-2005
use egrep

or [if on solaris] use '/usr/xpg4/bin/grep -E'
# 3  
Old 05-21-2005
And similarly on Linux (or any system that uses GNU grep)

grep -E

Cheers
ZB
# 4  
Old 05-21-2005
Thanks guys for your reply, egrep does the trick.

Now if wanted to change directory from home to "test" directory and do egrep what can I add to the beginning of the line so it changes directory and greps at the same time:
egrep -i -n error cl_less.out


Also I do egrep for a few files at the same time, they have different names so there is no pattern, I just add them one after the other and execute.

but there is an egrep I perform where there is a pattern:

egrep -i -n error cl_less1.out cl_less2.out cl_less3.out cl_less4.out

How can shorten this command and egrep just for these files.

Again your help is most appreciated!!!
# 5  
Old 05-21-2005
If I understand you correctly

cd /path/to/test && egrep -i -n error cl_less*.out

Or easier still, you don't need to cd

egrep -i -n error /path/to/test/cl_less*.out

Cheers
ZB
# 6  
Old 05-26-2005
Thanks ZAZZYBOB for you help!!!
This option: egrep -i -n error /path/to/test/cl_less*.out is working great with files that have the same name or follow a pattern.
But if I try the same option with files of different names it's not working, I tried this:
egrep -i -n error /path/to/test/cl_less.out more.out test.out
but it errors and it seems to find only the first file in the sequence, saying it can not open the other files.
I can not egrep for *.out because there would be too many files, is there any changes I can do so that it will change directory and egrep several files with different names?
NOTE: if I change directory first then egrep -i -n error cl_less.out more.out test.out it does work, but I want to be able to change directory at the same time.

your help is very much appreciated!!
# 7  
Old 05-26-2005
Quote:
Originally Posted by sqloyd
egrep -i -n error /path/to/test/cl_less.out more.out test.out
but it errors and it seems to find only the first file in the sequence, saying it can not open the other files.
I can not egrep for *.out because there would be too many files, is there any changes I can do so that it will change directory and egrep several files with different names?
NOTE: if I change directory first then egrep -i -n error cl_less.out more.out test.out it does work, but I want to be able to change directory at the same time.

your help is very much appreciated!!
the succeeding argument files have no associated paths but the first one does ... fixed by doing a cd to the directory in question ...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Echo and grep issues

Is there an environment issue that would not allow the following not store and pass the value into this field: underScorePresent=`echo $USER | grep "_" | wc -l` It is running on a new redhat 6.5 OS. The value $USER is set to cpac. It is a vendor code and they are saying it is environment... (1 Reply)
Discussion started by: mrn6430
1 Replies

2. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

3. UNIX for Dummies Questions & Answers

Piping grep into awk, read the next line using grep

Hi, I have a number of files containing the information below. """"" Fundallinfo 6.3950 14.9715 14.0482 """"" I would like to grep for Fundallinfo and use it to read the next line? I ideally would like to read the three numbers that follow in the next line and... (2 Replies)
Discussion started by: Paul Moghadam
2 Replies

4. UNIX for Dummies Questions & Answers

Issues while pattern matching using grep

Hi, I have a file f1 wi the following data f1.txt ======== Report ID Report Name ----------------------------------------------------------------- Post Requests : 2 Post successes : 2 ============================================= I need to search for the... (2 Replies)
Discussion started by: RP09
2 Replies

5. UNIX for Dummies Questions & Answers

Bash - CLI - grep - Passing result to grep through pipe

Hello. I want to get all modules which are loaded and which name are exactly 2 characters long and not more than 2 characters and begin with "nv" lsmod | (e)grep '^nv???????????? I want to get all modules which are loaded and which name begin with "nv" and are 2 to 7 characters long ... (1 Reply)
Discussion started by: jcdole
1 Replies

6. Shell Programming and Scripting

Issues in grep command in Linux

Hi All I have a file containing following records: $HEW_TGT_DB2_USER=hbme_bi2 $prmAttunityUser=ais $DS_USER=hbme_bi2 $prmStgUser=hbme_bi2 $prmuser=hbme_bi2 $prmStgPass=hbme_bi2 $prmpwd=hbme_bi2 $prmAttunityUser=ais Say suppose the name of the file is test4.txt When i fire this... (5 Replies)
Discussion started by: vee_789
5 Replies

7. Shell Programming and Scripting

grep for certain files using a file as input to grep and then move

Hi All, I need to grep few files which has words like the below in the file name , which i want to put it in a file and and grep for the files which contain these names and move it to a new directory , full file name -C20091210.1000-20091210.1100_SMGBSC3:1000... (2 Replies)
Discussion started by: anita07
2 Replies

8. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

9. Shell Programming and Scripting

Issues with grep -w

I am trying to use grep -w something as shown below. grep -w "$a" $LOG1 It is not giving me neither any error nor any data. I am facing the issue while i run this command inside a script. But i am getting the data if i run the above command outiside the script. here $a=08/11/2009 21 i... (13 Replies)
Discussion started by: rdhanek
13 Replies

10. Shell Programming and Scripting

MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else

Hi Guys, I need to set the value of $7 to zero in case $7 is NULL. I've tried the below command but doesn't work. Any ideas. thanks guys. MEM=`ps v $PPID| grep -i db2 | grep -v grep| awk '{ if ( $7 ~ " " ) { print 0 } else { print $7}}' ` Harby. (4 Replies)
Discussion started by: hariza
4 Replies
Login or Register to Ask a Question