Grep and ignore list from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep and ignore list from file
# 1  
Old 05-11-2017
Grep and ignore list from file

Code:
cat /tmp/i.txt 
'(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic Phone|ENCRYPTION)' 

grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE `cat /tmp/i.txt`
grep: Unmatched ( or \(

Please tell me why am i getting that

Last edited by Corona688; 05-11-2017 at 02:16 PM..
# 2  
Old 05-11-2017
Quote:
Originally Posted by jhonnyrip
cat /tmp/i.txt
'(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic Phone|ENCRYPTION)'

grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE `cat /tmp/i.txt`
grep: Unmatched ( or \(

Please tell me why am i getting that
`cat /tmp/i.txt` That outputs the content of /tmp/i.txt to grep and it interprets it as:
grep -iavE Regex FileName


Regex
Code:
'(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic

FileName
Code:
Phone|ENCRYPTION\)'

Do you see how it doesn't work?

What are you trying to do?
# 3  
Old 05-11-2017
grep ORA- from log files and ignore all pattern in i.txt
# 4  
Old 05-11-2017
Hi johnnyrip,
Please get into the habit of telling us what operating system and shell you're using when you post questions like this!

With your specific example, the following might work:
Code:
grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE "$(tr -d "'" < /tmp/i.txt)"

depending on what shell you're using. (It will not work with an original Bourne shell.)
# 5  
Old 05-11-2017
Quote:
Originally Posted by jhonnyrip
Code:
cat /tmp/i.txt 
'(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic Phone|ENCRYPTION)' 

grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE `cat /tmp/i.txt`
grep: Unmatched ( or \(

Please tell me why am i getting that
Hi,
there is a space in the file
Code:
...ORA-06512|Domestic Phone|ENCRYPTION)'
---------------------^

You may try this:

Code:
grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE "`cat /tmp/i.txt`"

...to avoid the shell's interpretation of the space.

Regards!
# 6  
Old 05-11-2017
Quote:
Originally Posted by AbelLuis
Hi,
there is a space in the file
Code:
...ORA-06512|Domestic Phone|ENCRYPTION)'
---------------------^

You may try this:

Code:
grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE "`cat /tmp/i.txt`"

...to avoid the shell's interpretation of the space.

Regards!
Note that according to post #1, the text in /tmp/i.txt contains leading and trailing single-quotes. It isn't clear to me whether those quotes were intended to quote the ERE being passed to the second grep or whether they are literal quotes that are to be matched by the ERE before and after one of the alternatives in the ERE. Your code assumes they are characters to be matched by the ERE. I thought they were intended to quote the ERE. Without a sample input file (i.e., one of the files matched by the filename matching pattern Rep*) we'll never know what the intent was. About all that we can say with any certainty is that the portion of the ERE that is the string |ORA-1017| is probably missing a digit somewhere before, after, or in the middle of 1017 (since the first grep is throwing away lines that don't have 5 digits after ORA-).
# 7  
Old 05-11-2017
@Don Cragun
This is the way that bash evaluates the single quote in Debian:

Code:
~$: grep -ia 'ORA-[0-9]\{5\}:' Rep* | grep -iavE "`cat /tmp/i.txt`"
+ grep -ia 'ORA-[0-9]\{5\}:' Rep-date
++ cat /tmp/i.txt
+ grep -iavE ''\''(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic
Phone|ENCRYPTION)'\'' '
ORA-20000:
ORA-20000:
ORA-20000:
ORA-20000:

Regards.

---------- Post updated at 09:22 PM ---------- Previous update was at 08:38 PM ----------

Quote:
Originally Posted by jhonnyrip
Code:
cat /tmp/i.txt 
'(ORA-28001|ORA-00100|ORA-28001|ORA-20026|ORA-20025|ORA-02291|ORA-01458|ORA-01017|ORA-1017|ORA-28000|ORA-06512|ORA-06512|Domestic Phone|ENCRYPTION)' 

grep -ia 'ORA-[0-9]\{5\}:' Rep* |grep -iavE `cat /tmp/i.txt`
grep: Unmatched ( or \(

Please tell me why am i getting that
You also can do it more simply,

Code:
cat /tmp/i.txt
ORA-28001
ORA-00100
ORA-28001
ORA-20026
ORA-20025
ORA-02291
ORA-01458
ORA-01017
ORA-1017
ORA-28000
ORA-06512
ORA-06512
Domestic Phone
ENCRYPTION

And then:

Code:
grep -ia 'ORA-[0-9]\{5\}:' Rep* | grep -iavE -f /tmp/i.txt

Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Grep to ignore suffix & find end of line

In COBOL, a hyphen can be used in a field name and in a specific program some field names would be identical to others except a suffix was added--sometimes a suffix to a suffix was used. For example, assume I am looking for AAA, AAA-BBB, and AAA-BBB-CCC and don't want to look at AAA-BBB-CCC... (7 Replies)
Discussion started by: wbport
7 Replies

2. Shell Programming and Scripting

Grep command to ignore line starting with hyphen

Hi, I want to read a file line by line and exclude the lines that are beginning with special characters. The below code is working fine except when the line starts with hyphen (-) in the file. for TEST in `cat $FILE | grep -E -v '#|/+' | awk '{FS=":"}NF > 0{print $1}'` do . . done How... (4 Replies)
Discussion started by: Srinraj Rao
4 Replies

3. Shell Programming and Scripting

Grep regex to ignore sequence only if surrounded by fwd-slashes

Hi, I've got a regex match to perform in a Bash script and can't quite get it right. Basically I want to match all IP address like sequences in a file which may or may not contain an IP address but with the extra qualification of ignoring any IP-like sequence which begins and ends with a... (27 Replies)
Discussion started by: gencon
27 Replies

4. Shell Programming and Scripting

script to ignore the user from list of users

Hi, I have a situation where I want to ignore few users from list of users and print rest of user in log file. say, I want to ignore aaa, bbb, ccc, ddd .. ppp from list of 20 user (do not want to include) What is the good command or any script? Thanks in advance. (1 Reply)
Discussion started by: sumit30
1 Replies

5. Shell Programming and Scripting

Grep but ignore first column

Hi, I need to perform a grep from a file, but ignore any results from the first column. For simplicity I have changed the actual data, but for arguments sake, I have a file that reads: MONACO Monaco ASMonaco MANUTD ManUtd ManchesterUnited NEWCAS NewcastleUnited NAC000 NAC ... (5 Replies)
Discussion started by: danhodges99
5 Replies

6. Shell Programming and Scripting

ignore fields to check in grep

Hi, I have a pipe delimited file. I am checking for junk characters ( non printable characters and unicode values). I am using the following code grep '' file.txt But i want to ignore the name fields. For example field2 is firstname so i want to ignore if the junk characters occur... (4 Replies)
Discussion started by: ashwin3086
4 Replies

7. Shell Programming and Scripting

how to grep a file in list

hi all, for an example: In a file out.txt contains: /export/home/raghu/bin/debug_serverLog_apache_20090626_0625.txt How to grep or cut the value as "debug_serverLog_apache_20090626_0625.txt" or i want only the output as "debug_serverLog_apache_20090626_0625.txt" pls advice me (3 Replies)
Discussion started by: raghur77
3 Replies

8. Shell Programming and Scripting

find grep and list file name

find . -exec grep "something" {} \; this command only show the grep data but doesn't show the file name and path, how to show file path in this command? (4 Replies)
Discussion started by: bill.zheng
4 Replies

9. Shell Programming and Scripting

Can we grep a list of all running PIDs in a file !!??

Hi, In the following part of a script, I am grepping the list of all running PIDs in the File as in line 3 :- $pid_count=`grep -c "^${pid_process}$" $CRI_PUSH_BIN_HOME/bin/ PushProcessId` If I cannot grep this way, then how can I do so. 1 pid_process=`ps -ef -o pid,args |... (1 Reply)
Discussion started by: marconi
1 Replies

10. UNIX for Dummies Questions & Answers

How will you list only the empty lines in a file (using grep)

How will you list only the empty lines in a file (using grep) (1 Reply)
Discussion started by: JosephGerard
1 Replies
Login or Register to Ask a Question