how to grep the contents of a variable..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep the contents of a variable..
# 1  
Old 01-07-2010
how to grep the contents of a variable..

Hello All,


I've written a script to collect all audit logs files; now i want to see only the files from it which contains certain x tablenames. I've stored all the tablenames in a log file and using it through variable in a script (ex:below)

Code:
$ more tablenames.log (this is just a samle tables there are more than 500 tables to search)
HRC1002
HRC1206
HRC1212
HRS1000
HRS1002
HRS1200
HRS1201

In a script:

Code:
TABLENAMES=/tmp/tablenames.log
SOURCE_FILES=/tmp/sys_audit_files.tmp
 
ls -1tr ${ORACLE_HOME}/rdbms/audit/*.aud > ${SOURCE_FILES}
(which collects more than 200 audit log files; and now i want to use a grep statment in a below for loop to search the tablenames.log file)
 
for i in `cat ${SOURCE_FILES}` ; do
    cat $i |  grep ?????? >> $LOGFILE
done

How do we use a variable or a logfile to grep

thanks in advance..

Last edited by Franklin52; 01-07-2010 at 05:59 AM.. Reason: Please use code tags!
# 2  
Old 01-07-2010
Use:

Code:
grep -f ${TABLENAMES} ${SOURCE_FILES}

instead of the for loop.
# 3  
Old 01-07-2010
Code:
find ${ORACLE_HOME}/rdbms/audit -name "*.aud" -exec grep yourstring {} \; >> $LOGFILE

Edit: I see you want to grep for every pattern found in a file, so use Franklins method

Last edited by funksen; 01-07-2010 at 06:10 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting the contents of a variable

i want to reduce the OPTIONS variable which is a list of email addresses to just the unique entries. The following works, but, i would like to accomplish it without using the temporary file (dest.txt) $echo $OPTIONS a b c A B D ... (5 Replies)
Discussion started by: jgt
5 Replies

2. UNIX for Dummies Questions & Answers

Problem to grep contents from a file

hi, I'm trying to grep content from one file in another file. The file that I'm searching into is large and hence I need to temporarily unzip it first. gzip -dc ALL.chr2.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz | grep '169997024\|190670539\|128051369' >... (2 Replies)
Discussion started by: janshamsani
2 Replies

3. Shell Programming and Scripting

Folder contents getting appended as strings while redirecting file contents to a variable

Hi one of the output of the command is as below # sed -n "/CCM-ResourceHealthCheck:/,/---------/{/CCM-ResourceHealthCheck:/d;/---------/d;p;}" Automation.OutputZ$zoneCounter | sed 's/$/<br>/' Resource List : <br> *************************** 1. row ***************************<br> ... (2 Replies)
Discussion started by: vivek d r
2 Replies

4. Shell Programming and Scripting

Grep contents from metastat command

Hi, after issuing metastat command I am getting output as follows Actually these soft partitions are more than 100. I want output as Device Name & Size. for eg d4004 2.0 GB (4 Replies)
Discussion started by: tuxian
4 Replies

5. Shell Programming and Scripting

How to read contents of a file into variable :(

My file is in this format : username : student information : default shell : student ID Eg : joeb:Joe Bennett:/bin/csh:1234 jerryd:Jerry Daniels:/bin/csh:2345 deaverm: Deaver Michelle:/bin/bash:4356 joseyg:Josey Guerra:/bin/bash:8767 michaelh:Michael Hall:/bin/ksh:1547 I have to... (1 Reply)
Discussion started by: dude_me5
1 Replies

6. UNIX for Dummies Questions & Answers

Grep the contents

Hi, Can I get the simple unix command or script to get the output as mentioned below. Input Contents: Processing file: home/j2ee-apps/web-estore/123.txt File: 123.txt Status: Locally Added Processing file: home/j2ee-apps/web-estore/META-INF/application.xml Processing file:... (4 Replies)
Discussion started by: vino_hymi
4 Replies

7. Shell Programming and Scripting

unique sort contents of a variable

Hi , I have #echo $var1 #hdisk2 hdisk3 hdisk0 hdisk2 Now I need to remove duplicate entries from this . ie. after sorting it should only have hdisk2 hdisk3 hdisk0 . I can have these values in a array as well . I understand we can use sort -u to remove the duplicates in a... (2 Replies)
Discussion started by: praveenbvarrier
2 Replies

8. UNIX for Dummies Questions & Answers

Save contents of a Variable

I want to save the contents of a variable to a file. How can that be achieved? I have tried with: echo $varname > textfile.txt but for some reason it does not print anything. (1 Reply)
Discussion started by: carl_vieyra
1 Replies

9. UNIX for Dummies Questions & Answers

how to strip out the contents of file using grep

Hi, I am receving a file from remote site which has EDI information for 830, 862 and 997 and I want to extect the data for 997 using grep's or any other methods. The data look like this: ISA~000 0000-0001-1000~997 AK1000~m 000~IEA~M ISA~000 0000-0001-1000~849 000~IEA~M ISA~000... (11 Replies)
Discussion started by: isingh786
11 Replies

10. Shell Programming and Scripting

adding contents of a variable to a command

hi all, i'm new to shell scripting, so i'm not sure how to work this. Is it possible to read in the contents of a variable and add it to a command? for example: ------------------------ #!/bin/sh set example = -dfr rm ${example} ------------------------ when i run the script, i want... (2 Replies)
Discussion started by: gammarays
2 Replies
Login or Register to Ask a Question