Hi Rudic Thank you for explanation.I understood your logic except the below.
As mentioned We will have multiple files in a folder with different file names we should pick only the files which start with abc_*_*.dat which came with in last 3 days.Can you please tell how we are doing this?
And also filetimestamp and the $THREEDAYSAGO values/format is fifferent .how we are comparing both? in if condition?Can you explain with example.
Filenames in folder:
Moderator's Comments:
Please use CODE tags as required by forum rules!
And, DON'T modify posts (here: #1) if others already referenced it, pulling the rug from under their feet!
Last edited by sunnykamal59; 12-05-2017 at 01:55 PM..
Reason: Added CODE tags and descritpion
My first and most important advice is that you apply utmost care when creating a post - watch your spelling, upper / lower case, punctuation, and data accuracy. Why should anybody care more for your posts than you do? Why should anybody want to guess what your problems are?
In your post#9:
- what is the C: for?
- you write "files which start with abc_*_*.dat" but post sample files like ghf_20171204.054340.dat - neither the abc nor the second _ appears; so: which one is valid? The code doesn't work with a wrong pattern.
- with "filetimestamp" you mean FILESTAMP? The latter is not directly compared to $THREEDAYSAGO but converted to seconds before the compare.
The result for the cited code is unpredictable as it depends on the number of files in that directory containing at least one _ character (disregarding the .dat ending). As said in post#10, the pattern does NOT match your target files.
Look into your shell's (which version you fail to mention, btw) man page for "Parameter expansion; Remove matching prefix / suffix pattern." to see how ${file#*_} and ${FILESTAMP%_*} are used to extract the time stamp from the file names. Also, use echo in the loop to print out the intermediate states of the extraction.
In post#6 you see date -d $FILESTAMP +'%s' used to convert the time stamp into epoch seconds for the comparison.
1)If we have multiple set of files in a folder like below, how we are looping each file for doing comparison?
2)for looping are we doing below logic in script?
3)if so can you please explain the above code with an example?
In all of your early posts you said that files were named using the pattern abc_YYYYMMDD_hhmmss.dat and the code that RudiC suggested processes the files that match the pattern you supplied.
When you then try running the code he suggested in a directory that doesn't have any files that match that pattern, the code won't find any files that match the pattern you told us all that you wanted to process. This is a classic example of what happens when you supply sample data that doesn't match your real data.
Feel free to modify the code RudiC suggested to match the format of the real filenames you are trying to process. Do not blame RudiC for supplying code that looked for what you said should be looked for when no files in that format are present.
To make the code match the latest sample names you have provided, you'll need to change the filename matching pattern in the for statement and change the parameter expansion that is used to extract the date from the expansion of the shell FILESTAMP variable.
I wan to pick the latest modified file name and redirect it to a file ..
ls -tr | tail -1 >file
but this is printing file ins side the filename ,
can anyone help me out (5 Replies)
Hi
In my script i am trying to access mainframe server using FTP,
in the server i have filee with the timestamp.I need to get the file with the latest timestamp among them . The server has the below files
/
ftp> cd /outbox
250 CWD command successful
ftp> ls
200 PORT command successful... (4 Replies)
Hi,
I have some list of directories in the form datemonthyear e.g. 02082009, 03082009 and 04082009 etc.
I need to pick the latest directory from the current working directory.
Outcome:
05082009
This is the output am expecting.
Thanks (6 Replies)
in the below .. i want to pick the latest logfile which is having JPS.PR inside..
that means i want particularly "spgport040408041223.log:@@@@@@@@ 04:13:09 Adding: JPS.PR."
which is latest among these..
is it possible to compare the current time with logfile time ?
reptm@xblr0758rop>... (4 Replies)
Suppose I have a unix file which contain a lost of 60 files like
filename1
filename2
...
..
...
filename60
I want to write a unix script that will pick up first 10 files in first run
10-20 files in 2 run
20-30 files in 3 run
30-40 files in 4 run
40-50 files in 5 run
50-60 files in 6... (1 Reply)
Hi All,
I have a file which contains the listing of another directory:
>cat list.dat
-rwxr-xr-x 1 test staff 10240 Oct 02 06:53 test.txtdd
-rwxrwxrwx 1 test staff 0 Oct 04 07:22 test.txx
-rwxrwxrwx 1 test staff 132 Sep 16 2007 test_tt.sh... (6 Replies)
I have a requirement which will select the files with a specific naming convention which got created in past 7 days in a specific directory.Lets say the directory is /data/XYZ and the file names follow the below nomenclature like Daily_File*.txt
I just need to create one CSV file which will... (12 Replies)
Hi ,
I have a file abc.txt which actually contains a directory and file list
-rwxrwxr-x 1 dmadmin mmasapp 334 Dec 03 2001 aafs_006.ksh
-rwxrwxr-x 1 dmadmin mmasapp 1270 Nov 13 2001 mcl_deposit_ftp.ksh
-rwxrwxr-x 1 dmadmin mmasapp 925 Oct 31 2001 ... (1 Reply)