![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting Files by date and moving files in date order | rebel64 | Shell Programming and Scripting | 2 | 03-11-2008 12:45 PM |
| Sorting by date and time | padmundo | UNIX for Dummies Questions & Answers | 7 | 07-10-2007 05:04 AM |
| Sorting a date coulumn | rinku11 | Shell Programming and Scripting | 2 | 05-15-2007 07:51 PM |
| date sorting | nmilella | UNIX for Dummies Questions & Answers | 3 | 07-11-2006 04:11 AM |
| sorting on date | Duckman | UNIX for Dummies Questions & Answers | 6 | 03-29-2001 04:32 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Date Sorting
Hi,
I have a list of files that take on the format ABCDE_yymmdd and wish to sort them in ascending date order. I can't use the unix time stamp for the file as this could possibly be different from the date given in the file name. Does anyone know of any way this can be done using unix shell scripting and/or awk(nawk)? What i already have: constructFileList() { if [ -f $DataDir/$FileListFile ] then rm -f $DataDir/$FileListFile fi for FILE in `ls -1 $DataDir/ABCDE_??????.dat` do echo $(basename $FILE)|nawk -f sort.awk done |sort|while read FILENAME do echo ${FILENAME#??????} >> $DataDir/$FileListFile done } The sort.awk script: function prisort(STRING) { return_str = substr(STRING,11,2) substr(STRING,9,2) substr(STRING,7,2) STRING return return_str } #Main Routine { print prisort($1) } Thanks Last edited by LiquidChild; 04-11-2007 at 04:38 AM.. |
|
||||
|
Wow, impressive, so much easier than what i was doing thanks anbu23, can you just give a brief explanation of what the -t "_" -k2 does, i would like to understand what I am using so I can build my knowledge.
Edit: I think i get what the -t option is for, to spilt the string to be able to sort on just the date part? Thanks. |
|
||||
|
Quote:
Use the single character char as the default field separator, instead of the default of whitespace. -k Define the sort key field. |
|
||||
|
Quote:
Code:
$ ls FILE_* FILE_010107.ok FILE_230580.ok FILE_230590.ok $ ls FILE_* | sort -t"_" -k2 FILE_010107.ok FILE_230580.ok FILE_230590.ok |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|