Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-21-2001, 03:50 PM   #1
LQ Newbie
Registered: Nov 2001
Posts: 8

Rep: Reputation: 0
Another daft newbie question

I have a timetable list that I have sorted every way I can while playing with the sort utility. However, thrown into my list are a July 98 & a Dec 98. the rest of the dates vary across the months from Jan - Dec 99. My question is this:
Is there a way I can sort the list to display the 2 98 dates first then followed by the 99 dates, all in monthly order? the year & month are seperates fields. I seem to only be able to sort either the monthly field or the yearly field. is there a way I can sort the first 2 lines & then resort the remainder of the file ignoring the first 2 lines? Apologies for the daft question but if we don't ask then we don't learn!
Old 11-24-2001, 11:03 AM   #2
Registered: Aug 2001
Location: UK
Posts: 48

Rep: Reputation: 15
Check the man page for sort... type 'man sort' at the prompt.

You need something like

sort -k5,6 -k1,3 ...

This sorts based on the year column first, then the month. I assume the month is only 3 characters in every line.

Old 11-24-2001, 02:39 PM   #3
LQ Newbie
Registered: Nov 2001
Posts: 8

Original Poster
Rep: Reputation: 0
I read the manual before posting. I already tried -k but it's still not sorting the way I want it to. There's always either 1 or 2 of the lines that are not sorted in the correct order. I have 6 columns (fields) in the timetable (index, month, date, year, departure, destination). If I type: sort +3 -4 -n +1 -2 -bM then I get 2 lines incorrectly placed in the sort & the monthly sort starts at March instead of January. It doesn't make any sense to me why it's sorting in this way. If I type: sort -k 4,5 -n -k 2,3 -bM I get the same result.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
daft desktop / gnome question gsd750 Linux - Newbie 2 09-10-2004 11:55 AM
Please answer some basic questions froma daft newbie jmpm Linux - Newbie 7 01-06-2004 07:49 AM
yet another daft floppy problem Bungholio Linux - General 5 07-07-2003 02:34 PM
Apache newbie question.. (very newbie question) tarballed Linux - Newbie 1 02-07-2003 09:41 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 01:53 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:27 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration