Hi,
Currently i wrote the script in this way (im a newbie)
Running in AIX
try like this
save the belows to a file for example get.awk
and run this
or
save the results of printf or any command's output to a tmpfile
regards
ygemici
Just use simple commands. ls, grep, sort, tail and xargs.
Just enhanced your sort command by reversing the sort order, to get the latest first.
This throws all files away older than the latest 3*4 files. 13 = 3*4+1.
Use ls and grep instead of getting "Argument list too long" when the directory got flooded since the last run.
---------- Post updated at 11:14 PM ---------- Previous update was at 04:43 PM ----------
Quote:
Originally Posted by bakunin
Instead of using printfand sort have a look at find, which does, what you want out of the box.
Imho the thread opener does not want files removed older than x-days, when there are no newer files around, otherwise after some days there wont be any versions left.
So find is not sufficient enough to get at least the 4 latest available days,
because they may be spread over more than 4 days or may be older.
Also it was stated that the inode-timestamps are not accurate, so the only trust is in the timestamp within the filenames.
Also it was stated that the inode-timestamps are not accurate
Where was that stated?
tail +13 does not work with tail from GNU coreutils, and although I don't know for sure, I kind of doubt it will work on AIX. But I generally agree with os-nix's approach. here is using sed instead of tail:
This will print all the filenames except the first (newest) 12. Then you can remove by piping to xargs rm:
Now i want to delete files with older date and keep 4 latest files available in the filename(no system timestamp here)
i interprete that "(no system timestamp here)" means, that last modification time is not usable. In real life sometimes files get touched by "accident". Or by "transporting" it with the wrong command or options.
Always use "-p" when using the cp command or other means to preserve times.
Quote:
tail +13 does not work with tail from GNU coreutils, and although I don't know for sure, I kind of doubt it will work on AIX. But I generally agree with os-nix's approach.
I agree when it comes to portability on some *nix boxes.
Another possibility is to use awk:
[CODE]
... | awk 'NR > 12' | ...
[CODE]
just output all lines after record 12
It's only a proposal, and there are several possibilities to get the desired result.
Just adopt to the platform and keep it simple.
Quote:
Originally Posted by mirni Where was that stated?
In the opening post:
I see. I misunderstood that this was some general statement about inode timestamps. They are indeed accurate, just not useable in the OP's case. All clear.
Hi All,
I have list of files like below with name abcxyz.timestamp. I need a unix command to pick the latest file from the list of below files. Here in this case the lates file is abcxyz.20190304103200. I have used this unix command "ls abcxyz*|tail -1" but i heard that it is not the appropriate... (2 Replies)
Hi,
I have two pipe separated files as below:
head -3 file1.txt
"HD"|"Nov 11 2016 4:08AM"|"0000000018"
"DT"|"240350264"|"56432"
"DT"|"240350264"|"56432"
head -3 file2.txt
"HD"|"Nov 15 2016 2:18AM"|"0000000019"
"DT"|"240350264"|"56432"
"DT"|"240350264"|"56432"
I want to list the... (6 Replies)
Hi ,
I did the initial search but could not find what I was expecting for.
15606Always_9999999997_20160418.xml
15606Always_9999999998_20160418.xml
15606Always_9999999999_20160418.xml
9819Always_99999999900_20160418.xml
9819Always_99999999911_20160418.xmlAbove is the list of files I... (4 Replies)
Hi,
I have requirement to list out files that are created after particular file.
ex. I have below files in my directory. I want to display files created after /dirdat/CG1/cg004440 file.
./dirdat/CG1/cg004438 09/07/14 0:44:05
./dirdat/CG1/cg004439 09/07/14 6:01:48 ... (3 Replies)
Hi Friends,
Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp
$ printf '%s\n' *.dat* | sort -t. -k3,4
filename_1.dat.20120430.Z
filename_2.dat.20120430.Z
filename_3.dat.20120430.Z
filename_1.dat.20120501.Z
filename_2.dat.20120501.Z... (1 Reply)
I have a few log files which get generated on a daily basis..So, I need to pick only the ones which get generated for that particular day.
-rw-r--r-- 1 staff 510732676 Apr 7 22:01 test.log040711
-rwxrwxrwx 1 staff 2147482545 Apr 7 21:30 test.log.2
-rwxrwxrwx 1 staff 2147482581 Apr 7 19:26... (43 Replies)
Hi,
With the help of below script im able to get the count of all the .xml files but that count is not specific to a day ie its the total count of all .xml files what i want is specific to 1 day and that of every half an hr ie from 23 feb 2009 7 am till 23rd feb 2009 2300 am and from 07:00 to... (1 Reply)
Dear All,
I have the followoing requirement..
REQ-1:
Suppose I have the following files
XX_20070202000101.zip
XX_20080223000101.zip
XX_20080226000101.zip
XX_20080227000101.zip
XX_20080228000101.zip
XX_20080229000101.zip
Suppose sysdate = 29 Feb 2007
I need to delete all files... (3 Replies)