Page 1 of 2

Extracting files from unix

Posted: Fri Apr 15, 2011 11:31 am
by times29
Hi,
I have few files on unix box want to pick up the latest file based upon the latest date what is best approach to do it

want to extract latest file which will be (111AAA_201102251428300731_test_code.csv)

Sample of iles on unix box

111AAA_201102251428300731_test_code.csv
1222AAA_201101041428300731_test_code.csv
1444AAA_2011010314283007311_test_code.csv

Thanks

Posted: Fri Apr 15, 2011 11:53 am
by asorrell
I'd usually do it from a job sequence. Do an execute command prior to job execution using "ls" with the appropriate wild card and options to return the correct filename first in its list.

Then use the command output status variable for that execute command to pass the correct filename to the job in a parameter.

Posted: Fri Apr 15, 2011 2:03 pm
by times29
Hi,
Can draw a flow diagram if possible

Thanks

Posted: Sat Apr 16, 2011 1:03 am
by karthi_gana
Use aggregator stage and max() function

Posted: Sat Apr 16, 2011 2:39 am
by zulfi123786
asorrell wrote:I'd usually do it from a job sequence. Do an execute command prior to job execution using "ls" with the appropriate wild card and options to return the correct filename first in its list.

Then use the command output status variable for that execute command to pass the correct filename to the job in a parameter.
The same can be done using before job subroutine if a sequence job is not preferred.

Posted: Sat Apr 16, 2011 6:50 am
by chulett
No, it cannot if the goal is to pass the output of the routine into the job as a job parameter value.

Posted: Sat Apr 16, 2011 7:33 am
by times29
That is right we need to pass the routine as job parameter value i can run script below to see that file on aix box but how pass the below script to a file.
ls -1 *.csv | sort -n -t"_" -k 2.1,2.6 | tail -1

Posted: Sat Apr 16, 2011 7:37 am
by chulett
Andy has already explained how to do that.

Posted: Sat Apr 16, 2011 7:55 am
by zulfi123786
zulfi123786 wrote: The same can be done using before job subroutine if a sequence job is not preferred.
Not exactly the same thing but you could have a small script that copies/moves the most latest file to a file say xxx.dat and use the same xxx.dat in the seq file stage.

Run the script using before job subroutine.

Posted: Sat Apr 16, 2011 10:30 am
by times29
i am passing file name in sequential file and its not liking it i just want to test it before passing parameters

/aa/test/latestfile=$(ls *.csv | sort -nt_ -k2.1,2.6 | tail -1)

Posted: Sat Apr 16, 2011 11:20 am
by chulett
Well, what the heck does "not liking it" mean? :?

Posted: Sat Apr 16, 2011 11:49 am
by times29
mean i can't view data as no file is found but i can see data if i give
same path name with specific file name

Posted: Sat Apr 16, 2011 3:17 pm
by chulett
times29 wrote:i am passing file name in sequential file and its not liking it i just want to test it before passing parameters

/aa/test/latestfile=$(ls *.csv | sort -nt_ -k2.1,2.6 | tail -1)
What does this mean? If this is what you put in the Sequential File stage as the filename, you can't do any such thing. What you can do is put those commands into an Execute Command stage in a Sequence job and then pass $CommandOutput to a Job Activity stage as a parameter value... as Andy noted.

Posted: Sat Apr 16, 2011 4:15 pm
by ray.wurlod
Are you giving this expression as the file name or as the filter command?

Posted: Sun Apr 17, 2011 1:23 pm
by times29
Hi,
Don't understand what Andy is saying i put the command in execute command stage and it did return reply 0 which is desired output and in the next sequence i have a job in which this ouput need to be passed my question is where should i put this ouput as input as Chulett said ($CommandOutput to a Job Activity stage as a parameter value)

So what i understand is INPUT_FILE_NAME value expression will be $CommandOutput in job activity for job 2 as job 1 will create ouput command as below


Output from command ====>
/aa/test/aa_201005051223400386_test1.csv (from job 1)

so job 2
INPUT_FILE_NAME value expression will be $CommandOutput

Is that right

Thanks