Improving find to read table name from file


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Improving find to read table name from file
# 1  
Old 04-14-2016
Improving find to read table name from file

Hi there,
I currently use the following find command to recursively search all the subdirectories in our file system for a table ( in this case BB_TENURE_DAYS)

Code:
find -type f -exec grep -l "BB_TENURE_DAYS" {} \+

So I have this so far - the problem is how do I read the line to get the tablename

]
Code:
for line in `cat /tmp/$$controlFilesFound.txt`
        do
          #get filename some how
      
          find -type f -exec grep -l "$filename" {} \+
        done

how do I pick the filename up - it is the only field in the file

Many thanks
Rob..

Last edited by rjsha1; 04-14-2016 at 07:51 AM.. Reason: more code added
# 2  
Old 04-14-2016
Quote:
Originally Posted by rjsha1
Code:
find -type f -exec grep -l "BB_TENURE_DAYS" {} \+

grep can be made to work on all files in a directory, so (something like) this might speed things up:

Code:
find . -type d -exec grep "BB_TENURE_DAYS" {}/* \;

Quote:
Originally Posted by rjsha1
So I have this so far - the problem is how do I read the line to get the tablename
Code:
for line in `cat /tmp/$$controlFilesFound.txt`
        do
          #get filename some how
      
          find -type f -exec grep -l "$filename" {} \+
        done

how do I pick the filename up - it is the only field in the file
In this case it lands on <stdout>, so you can pick it up by a simple redirection, pipeline or something such:

Code:
for .... ; do
     .....
done > /some/file

for .... ; do
     .....
done | read VAR

But your loop is a little flawed. Consider:

Code:
while read line ; do
     [....]
done < /tmp/$$controlFilesFound.txt

instead. I usually add provisions to be able to add comment lines like in shell so that i can put notes for myself into the config files. I also filter out empty lines and whitespace prior to reading the file ("<b>" and "<t>" is a literal blank and tab character) This looks like:

Code:
sed 's/#.*//;s/^[<b><t>]*//;s/[<b><t>]*$//;/^$/d' /tmp/$$controlFilesFound.txt |\
while read line ; do
     [....]
done

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Old 04-14-2016
many thanks - it's been a while since I have done unix stuff - it's all coming back to me 0Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find particular file-name in file and get result in table in mail?

We have 100 linux servers, All send logs to both centralize server(server1 and serverb). all send logs every day and stores in /syslog folder with hostname.log file. I need to prepare script to check every day from both centralize server(server1 and serverb) and send mail in table format. ... (1 Reply)
Discussion started by: yash_message
1 Replies

2. UNIX for Beginners Questions & Answers

Read Table in file and split

HELLO I need your help please , i need to read a file that contain a table like : Name | Status ------------------ DB 1 | UP DB 2 | UP DB 3 | DOWN DB 4 | UP DB 5 | UP the objective to read each line and check if DB is UP or Down and give me the name of Down database.... (10 Replies)
Discussion started by: Abdellah
10 Replies

3. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

4. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

5. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

6. Shell Programming and Scripting

Read parameter file in a shell script to unload a DB2 Table???

Hi , I Have following requirement: DB2 Sql query to pass from a parameter file for example, I would create a parameter file with (SELECT column 1, column 2 FROM Table name) then job would read it and create a file with the contents named table.txt How to write/modify below ksh script to... (10 Replies)
Discussion started by: developer.dwh9
10 Replies

7. Shell Programming and Scripting

Read Table,View,Package,Function and Procedure Name in a File

Hi I am new to Unix shell scripting. But i need help to slove the below issue. Issue description: I want to read table, view names and package names in a file my plan to find the table name is : search "From" key word find the table or view To find the packge name : Search "Package... (5 Replies)
Discussion started by: sboss
5 Replies

8. Shell Programming and Scripting

shell script to read data from text file and to load it into a table in TOAD

Hi....can you guys help me out in this script?? Below is a portion text file and it contains these: GEF001 000093625 MKL002510 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL003604 000001 000000 000000 000000 000000 000000 000001 GEF001 000093625 MKL005675 000001... (1 Reply)
Discussion started by: pallavishetty
1 Replies

9. UNIX for Dummies Questions & Answers

improving my script (find & replace)

Hi all, I have a script that scan files, find old templet and replace it with new one. #!/bin/ksh file_name=$1 old_templet=$2 new_templet=$3 # Loop through every file like this for file in file_name do cat $file | sed "s/old_templet/new_templet/g" > $file.new #do a global searce and... (8 Replies)
Discussion started by: amir_yosha
8 Replies
Login or Register to Ask a Question