Hi,
I have a situation, I get ONE file everyday through FTP in my unix box. That file name varies depending on the source that is sending the file to us. I have created a generic file called LOAD.TXT file. DataStage points to this file. Everyday in Unix I copy the content of the newly ftped file to LOAD.TXT. I use this command cat ftped filename > LOAD.txt to copy the content.
I am trying to automate this process. I am trying to write a shell script that picks up the latest file in the directory(i.e. newest file that comes in) and pass the content of that file to LOAD.TXT. This script will be called by DataStage on the "Before job Routine".
I am little new to Unix and need some help/advice on the script. I tried something like:
var1=ls -1t | head -1 --> This line picks up the newest file in the directory.
cat $var1>LOAD.txt
I error out on the first line of my script.
Also I tried something like ls -1t | head -1 | cat >load.txt. But I am not getting the desired result.
Is their a way to pass the output of the line below to a variable var1.
ls -1t | head -1. Or Is their a better way to do through DataStage.
I will really appreciate any help in this regards.
Thanks
Raj
Copying Content of a Newest file
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Just make it a single command, using backquotes to capture the output of the pipeline.
Why cat? Surely a cp command would be more efficient.
Maybe you want to remove load.txt first. No problem.
You probably also want to cater for the case that there are no files in the directory, in which case the cp command would fail.
Code: Select all
cat `ls -1t | head -1` > load.txt
Code: Select all
cp `ls -1t | head -1` load.txt
Code: Select all
rm -f load.txt ; cp `ls -1t | head -1` load.txt
Code: Select all
rm -f load.txt ; ls -1t * && cp `ls -1t | head -1` load.txt
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Premium Member
- Posts: 483
- Joined: Thu Jun 12, 2003 4:47 pm
- Location: St. Louis, Missouri USA
-
- Premium Member
- Posts: 483
- Joined: Thu Jun 12, 2003 4:47 pm
- Location: St. Louis, Missouri USA