Shell script for sorting files with same extension(.xml,.dat etc..)in a directory in
Hi,
Pls help me in writing a shell script for sorting the below files w.r.t latest date. here date is within the file name, not according to the system date. for example given files: format is XXXXXX_YYYYMMDDHHMMSS-RequestID.xml abcdef_20140713114020-abc123.xml tuvwxy_20140716134520-abc123.xml hijklm_20140714123040-abc123.xml nopqrs_20140712104010-abc123.xml Sorted order is : nopqrs_20140712104010-abc123.xml abcdef_20140713114020-abc123.xml hijklm_20140714123040-abc123.xml tuvwxy_20140716134520-abc123.xml Thanks, Santosh |
Hi,
Quote:
Quote:
Quote:
Code:
ls -t -1 *.xml Quote:
Evo2. |
Hi Evo,
Thanks for the quick response..Pls help me how to incorporate the below files which are to be sorted.pls share any template for better understanding. Files to be sorted abcdeg_20070809141159.xml abcdeg_20070809141157.xml abcdeg_20070809141155.xml abcdeg_20070809141151.xml abcdeg_20070809141149.xml abcdeg_20070809141148.xml Then The Sorted Order is abcdeg_20070809141148 abcdeg_20070809141149 abcdeg_20070809141151 abcdeg_20070809141155 abcdeg_20070809141157 abcdeg_20070809141159 Thanks, Santosh |
Hi,
So you want to sort them my name.. that is the default sort order for both a shell glob and ls. Eg Code:
ls -1 Evo2. |
Hi,
consider the files are like below: Format: yyyyMMdd_hhmmss-filename.xml 20140710_111936-xyz.xml 20140708_111740-abc.xml 20140705_112550-def.xml Sorting order should be w.r.t latest date first.The order should be: 20140708_111740-abc.xml 20140705_112550-def.xml 20140710_111936-xyz.xml(latest date should appear last) Now, I need to check the date and time stamp as available in the file names (and not the unix system date timestamp), compare it, and pick up the file with the lowest date timestamp in its name, first and latest date at last. Hope you got my point. Thanks, Santosh |
Hi,
Quote:
Code:
ls -1 Code:
echo * | tr ' ' '\n' Quote:
Quote:
Code:
first=$(echo * | tr ' ' '\n' | head -1) I have to admit I'm pretty lost. I really don't know what you are trying to do. Again, giving the bigger picture would help. I suspect if you learn just a little bit of how to use the command line you'd be trivially able to do what you want, but since I don't understand what you are trying to do I don't think I can help. Evo2. |
ls -ls *.xml I think it can help you
|
Sorting files wrt date within filename
Hi,
Pls help me in writing a shell script for sorting the below files w.r.t latest date. here date is within the file name, not according to the system date. for example given files: format is XXXXXX_YYYYMMDDHHMMSS-RequestID.xml abcdef_20140713114020-abc123.xml tuvwxy_20140716134520-abc123.xml hijklm_20140714123040-abc123.xml nopqrs_20140712104010-abc123.xml Sorted order is : nopqrs_20140712104010-abc123.xml abcdef_20140713114020-abc123.xml hijklm_20140714123040-abc123.xml tuvwxy_20140716134520-abc123.xml Thanks, Santosh |
Hi,
ok, so the files are not as you described them in your earlier posts. You can use sort for this. Eg sorting on everything after the underscore: Code:
ls -1 | sort --field-separator=_ --key=2 |
All times are GMT -5. The time now is 07:43 PM. |