The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Searching filenames containing certain text??? skyineyes UNIX for Advanced & Expert Users 6 01-16-2008 07:48 AM
Search for strings & copy to new file amitrajvarma Shell Programming and Scripting 2 11-25-2007 11:51 PM
Search between strings with an OR pbsrinivas Shell Programming and Scripting 3 07-12-2007 05:46 AM
Perl code to search for filenames that contain special characters jerardfjay Shell Programming and Scripting 8 01-19-2006 04:31 PM
searching for strings/user IP addresses 30694 UNIX for Dummies Questions & Answers 2 09-23-2002 03:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-08-2005
pathanjalireddy pathanjalireddy is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 21
Arrow 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 (permalink)  
Old 06-08-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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 (permalink)  
Old 06-08-2005
pathanjalireddy pathanjalireddy is offline
Registered User
  
 

Join Date: Apr 2005
Posts: 21
Hi,

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

emdc_value, emdc.table, $emdc
  #4 (permalink)  
Old 06-08-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0