about unix

i want to get the latest file from the directory ...

then extract the specific lines from it(the latest file which i extracted) starting from the charcters ...INSTANCEID ...Program started at.... program ended at ....

i want to do it for the multiple dirctories at the same time

could anyone give me the script for this

You really did not provide much detail - examples of input and desired output. However, the following should get you started. See what you can write of a script, and post back follow-up questions.

Either of the following will give you the latest (most recent file). There are many ways to find this out, by the way.

> ls -lt | grep "^-" | head -1 | awk {'print $9'}
comp.log
> ls -lt | grep "^-" | head -1 | tr -s " " | cut -d" " -f9
comp.log

you can set a variable for the results, with

file1=$(ls -lt | grep "^-" | head -1 | awk {'print $9'})

A script can then cat or head or grep on $file1
I would suggest trying to do this for one file. Once you can do that, it is farily easy to insert the command(s) into a loop function.

Hello there

thanu for ur reply.....but i m not getting the desired output

ill explain u in detail.....wht we do

we first use the command ls -lt /apps/psoft............../FNTEDP01*

through which we get the no of files in the directory of the format

/apps..................../FNTEDP01_1423165.LOG

from this we pick the latest file as per the date

and then use more command to get the information and then the tail command if we dont get the entire information from the more

(we dont use the cat command bec some of the files may be very large )

then pick the information from the file

we do this for several files ....

Hi ,

Kindly check whether the below script is working or not.

file = `ls -lt | grep "^-" | head -1 | awk { print $9 }`
cat file | grep "^FNTEDP01" > file1
for i in `cat file1`
do
more $i
done

Thanks and Regards,
JeganR

Command we tried using to grep ERROR from lastest 1 log files from 5 logs files available in that particular directory is:
grep ERROR 'ls -ltr | tail -1'

but this command is not working.. for me its saying.. cannot open DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log

if i give ls -lrt for all the files in that diretory

-------r-- 1 egdevbb intdev 5022 Apr 2 05:13 DistributeDataFilesToTarget_4_dataLocations_ChinaDataLocations.xml.log
-------r-- 1 egdevbb intdev 1672 Apr 2 05:14 DistributeImageFilesToTarget_14_dataLocations_WHQDataLocations.xml.log
-------r-- 1 egdevbb intdev 7480 Apr 2 05:15 DistributeImageFilesToTarget_60_dataLocations_IndonesiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2113 Apr 2 05:34 DistributeImageFilesToTarget_8_dataLocations_MalaysiaDataLocations.xml.log
-------r-- 1 egdevbb intdev 2107 Apr 2 05:39 DistributeImageFilesToTarget_10_dataLocations_PhillipinesDataLocations.xml.log