Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting a text file

Status
Not open for further replies.

BIS

Technical User
Jun 1, 2001
1,893
NL
Hello,

Sorry for asking a myriad questions lately, and many many thanks to the people who have helped me so far.

I have a text file like this:

;930;47;15;203;6738;15
;1030;63;20;271;10500;20
;1100;40;24;327;10172;24
;1200;28;16;217;9461;16
;1400;18;14;191;9136;14
;1530;32;21;292;10670;21
;1600;33;23;316;11325;23
;1730;71;26;355;17304;26
;1830;22;16;214;7889;16
;1900;14;10;133;7455;10
;2100;4;3;41;4535;3
;2130;0;0;0;0;0
;2230;0;0;0;0;0
;0;0;0;0;0;0
;730;0;0;0;0;0
;830;0;0;0;0;0

The first 'column' after the first semi-colon is a time stamp. Is there a way (i am sure there is) to have this sorted by this 'column' ?

 
Use sort

sort yourfile

or

sort -b +1 yourfile

the -b ignores leading spaces

the +1 tells it to sort on the first column

you may have to pad the fields out to 4 chars --
| Mike Nixon
| Unix Admin
| ----------------------------
 
sort -t ';' -k 2n myText.txt vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
ok that seems to work. how do I 'pad' them out?
for example 730 would need to be 0730 ?
 
vlad - absolutely excellent stuff - thank you ever so much.

if its not too much trouble, could you quickly run over that sort statement for me?

If you want stars (which I just noticed I have forgotten to give you) please let me know.

I guess now is the time to sit back and start learning a bit.

As you no doubt will have noticed I am pretty new to scripting. There are so many different utilities out there, sed, awk, nawk, sort, tr, etc etc. Where would be the best place to start?
 
hi,
sort -t';' +1n filename

-t is delimeter which is ;
+1 is first column
n is numeric

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top