Quote:
Originally Posted by
blowtorch
vgersh99, can you please explain the nawk? Didn't get it...
the objective is to get '20070809141159 Ack_to_MDS_20070809141159.xml' out of 'Ack_to_MDS_20070809141159.xml'; sort the file names; remove '20070809141159' (in our case) the prefix leaving the 'suffix' (the file name itself) - this will give us the sorted list of files based on the embedded timestamp.
What's the 'embedded timestamp' in the file name? The 'embedded timestamp' if the next to the last field in the '_' OR '.' filename.
'nawk' takes the next to the last field of all the wild-carded filenames and makes the timestamp from the filename a 'prefix' followed by the value of 'OFS' (space) followed by the $0 (filename).
we sort numerically '-n' - having the timestamp appearing as a prefix, make the sort work as expect.
once sorted, we remove the 'prefix' (timestamp) with the 'cut' command.
The end result is a list of file names sorted by the embedded timestamp.
And the rest is our editting/grepping body of the loop.