searching for filenames with search strings in another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting searching for filenames with search strings in another file
# 1  
Old 06-08-2005
CPU & Memory searching for filenames with search strings in another file

Hi,

I have 5 files in a directory.

emp1_usage.txt
emp2_usage.txt
emp3_usage.txt
emp4_usage.txt
emp5_usage.txt

I am using sqlldr to get the contents of the above 5 files and store it in a temp table and update my original table using temp table.

for f in *emp*.txt
do
sqlldr usr/passwd control=data.ctl data=$f
done


Now, the problem i got is:

I have a table called 'emdc' in which one column has the values:

emp_name
------------
emp1
emp2
emp3

I should dynamically check what are the values in the emdc table and pass to the sqlldr those file-names which have the values in the emdc table.

Let me explain Clearly:

I should now process only emp1_usage.txt, emp2_usage.txt, emp3_usage.txt into the sqlloader.

The script should automatically check for the values in emdc table and process only the 3 files among the 5 files present in the directory.

Please send me the snippet of the code.

Thanks in advance...........
# 2  
Old 06-08-2005
Check this out...

There are somethings which you need to re-write. I will say what those are, at the end.


#! /bin/sh

while read line
do
emdc_value=${emdc_value}" "`echo $line | awk -F"[ ]*" '{ printf $1 }'`
done < emdc.table

for f in $emdc
do
sqlldr usr/passwd control=data.ctl data=$f
done

emdc.table contains

emp_name
------------
emp1
emp2
emp3

In the awk part of the script, you will need to modify the argument passed to printf. Right now I am assuming that in line 1, emp1 is the first field; line 2 , emp2 is the first field. Also the other assumption, the delimiters between the different fields of each line is space.
You will need to change those to suit your emdc.table configuration.

Havent tested it. Didnt have an input file.

Post the results if the script breaks somewhere.

Vino
# 3  
Old 06-08-2005
Hi,

I am not clear with variables u have used in the shell script.

emdc_value, emdc.table, $emdc
# 4  
Old 06-08-2005
The script again is,

Code:
#! /bin/sh

while read line
do
emdc_value=${emdc_value}" "`echo $line | awk -F"[ ]*" '{ printf $1 }'`
done < input

for f in $emdc_value
do
sqlldr usr/passwd control=data.ctl data=$f
done


Hope this makes it more clear.

After the while loop is read completely, emdc_value should contain the values, emp1, emp2 emp3.. i.e. entries from the input file ( your emdc table).

vino
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

2. Shell Programming and Scripting

Searching the content of one file using the search key of another file

I have two files: file 1: hello.com neo.com,japan.com,example.com news.net xyz.com, telecom.net, highlands.net, software.com example2.com earth.net, abc.gov.uk file 2: neo.com example.com abc.gov.uk file 2 are the search keys to search in file 1 if any of the search key is... (3 Replies)
Discussion started by: csim_mohan
3 Replies

3. Shell Programming and Scripting

Searching same filenames in different partitions

Hi, We are doing some migration work. The same files may exist in different partition/mountpoints. We may place it in a single place, hence we don't want any duplicates...we will rename the file names if we know the files which has duplicates(by file name)). It would be nice if a script... (3 Replies)
Discussion started by: saravanapandi
3 Replies

4. Shell Programming and Scripting

Searching for a list of strings in a file with Python

Hi guys, I'm trying to search for several strings, which I have in a .txt file line by line, on another file. So the idea is, take input.txt and search for each line in that file in another file, let's call it rules.txt. So far, I've been able to do this, to search for individual strings: ... (1 Reply)
Discussion started by: starriol
1 Replies

5. Shell Programming and Scripting

Grep and replace multiple strings in a file with multiple filenames in a file

Hi, I have a file containing list of strings like i: Pink Yellow Green and I have file having list of file names in a directory j : a b c d Where j contains of a ,b,c,d are as follows a: Pink (3 Replies)
Discussion started by: madabhg
3 Replies

6. UNIX for Dummies Questions & Answers

Searching for a pattern from filenames stored in a file

Hi, I have got some 10 filenames stored in a file or displayed in the console as a result of some query i made.. Now I need to open each of these files and search for a pattern in these 10 files.. Can someone help me with this? Thanks, Jean (9 Replies)
Discussion started by: jeanjkj
9 Replies

7. UNIX for Dummies Questions & Answers

Searching by date range from filenames

Hello all, i have tons of files in folder named like this (yyyymmdd): bookcollection20100729 bookcollection20100730 bookcollection20100731 bookcollection20100801 bookcollection20100802 etc. I need to find files with date range in there names lets say from 2010.07.30 - 2010.08.02 ... (10 Replies)
Discussion started by: Whit3H0rse
10 Replies

8. UNIX for Dummies Questions & Answers

Searching for specific filenames

Hi I would like to know how to search through a directory and pull out files that has a specific pattern in the filename. For example if the filename has "bsc" in it, then that file must be moved to another directory where I will perform some operations on it. I know grep can be used, but I'm... (17 Replies)
Discussion started by: ladyAnne
17 Replies

9. UNIX for Dummies Questions & Answers

Searching a file with exclusion in the search

Hello, I'm looking for a bit of help. Im trying to search a file for lines that contain white spaces at the end of the lines. This is what I'm using where $param is the path and file name and it redirects the output to a txt file : echo | grep -n ' $' $param >> $2 Is it possible to have... (8 Replies)
Discussion started by: gintreach
8 Replies

10. UNIX for Advanced & Expert Users

Searching filenames containing certain text???

Suppose there are multiple files containing certain text "abc". How to print the name of all such files with a single command from unix prompt? Thanks in advance (6 Replies)
Discussion started by: skyineyes
6 Replies
Login or Register to Ask a Question