The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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
sort text file naamas03 Shell Programming and Scripting 4 08-04-2009 08:51 AM
egrep not giving desired results igandu Shell Programming and Scripting 3 11-14-2007 04:43 AM
Perl Sort on Text File eltinator Shell Programming and Scripting 6 08-07-2007 02:20 PM
Need a Help with sort a text file with some fields alexcol Shell Programming and Scripting 3 02-19-2007 03:13 AM
How to sort find results groundlevel UNIX for Dummies Questions & Answers 8 11-09-2005 02:36 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 3 Weeks Ago
JakeKatz JakeKatz is offline
Registered User
  
 

Join Date: Nov 2009
Location: Ottawa, ON. Canada
Posts: 3
HELP: I need to sort a text file in an uncommon manner, can't get desired results

Hi All

I have a flat text file. Each line in it contains a "/full path/filename". The last three columns are predictable, but directory depth of each line varies.

I want to sort on the last three columns, starting from the last, 2nd last and 3rd last. In that order. The last three columns have a constant column width:

Code:
/../...../.../2009/365/2300.Z
Last col(6): 24h time 0000.Z -> 2300.Z (compressed file)
2nd Last col(3}: Day of Year, 001 -> 365 (366 in leap years)
3rd Last col(4): Year

I'll explain with an example:

- desired sort key: last col, 2nd last col, 3rd last col

Example: (unsorted)

Code:
cat dirList.txt

/home/jake/quarterly/2009/307/1300.Z
/home/jake/quarterly/2009/303/1400.Z
/home/jake/bimonthly/submitted/2009/007/1800.Z
/home/jake/yearly/2009/199/2300.Z
As you can see, the number of columns in this example vary, however, regardless the number of columns, I would like to sort the lines based on last, 2nd last & 3rd last columns, the results should look like this:

Code:
cat dirList.txt | unix | magic | commands | here

/home/jake/bimonthly/submitted/2009/007/1800.Z
/home/jake/yearly/2009/199/2300.Z
/home/jake/quarterly/2009/303/1400.Z
/home/jake/quarterly/2009/307/1300.Z
Perhaps an awk + sort command line combo will do the trick, but I'm Google'd out on searching for an answer.

Any help would be greatly appreciated.

Tks,
Jake.

Last edited by pludi; 3 Weeks Ago at 12:04 PM.. Reason: code tags, please...
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0