Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Feeding input using a text file

Status
Not open for further replies.

limester

Technical User
Dec 29, 2004
69
CA
Hello!

I command in a script that I would like to run against the contents of a text file by adding to the script. This text file just one entry for each line, so the script would parse this:

line1
line2
line3
.....etc

Any help would be greatly apprecited!
 
Hi Let me add to this request above as it woul dbe nice to have the following:

Each line item in the text file is from a query to a database and has a special naming convention:

example
filename.txt
012YYYYMMDDHHMMSS
012YYYYMMDDHHMMSS
012YYYYMMDDHHMMSS
....

each line is unique. I am using a rcp command to copy the file to another server. the server stores the file as /YYYY/MM/DD/filename

If it could parse the text file, build the directory structure, and then rcp the file, that would be perfect. I have a simple rcp script, but as there are so many entries, it is a lot of manual work

any help would be greatly appreciated!
 
This should be posted in Unix Scripting.

What shell?
Are you tring to read a single line as input? The phrase "by adding to the script" throws me off.
 
Something along these lines perhaps? I'm assuming the destionation directory already exists.

Code:
#!/usr/bin/ksh

while read line
do
        year=$(expr substr "$line" 4 4)
        month=$(expr substr "$line" 8 2)
        day=$(expr substr "$line" 10 2)
        echo rcp somefile remotehost:/$year/$month/$day/
done < filename.txt

Remove the echo when you're satisfied with the output...

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top