You are not logged in.

#1 2010-12-13 08:41:34

omgwtfbyobbq
Member
Registered: 2006-07-04
Posts: 226

Ordering the output of locate

I have a bunch of html files (chapters of an online book) I want to feed htmldoc. The problem I have is that the output of locate goes 1, 10, 11, 12, ..., 19, 2, 20, 21, .... and so on. What program can I use so that the locate output (variable htmldoc is using in the script) is in the right order?

Offline

#2 2010-12-13 09:06:27

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,399
Website

Re: Ordering the output of locate

locate ...  | sort -h

Offline

#3 2010-12-14 05:38:05

omgwtfbyobbq
Member
Registered: 2006-07-04
Posts: 226

Re: Ordering the output of locate

I forgot to mention, in locates output it's chapter1, chapter10, and so on. I've tried sort, but I don't see anything about restricting the sorting to only letters. Can sort ignore letters, or do I need to use something like sed to strip out the  "chapter" prefix in the file name and then put it back in after sort is done?

Offline

#4 2010-12-14 09:09:39

kwirkie
Member
Registered: 2010-01-09
Posts: 15

Re: Ordering the output of locate

If all the files start with 'chapter' you can use

sort -k1.8n

The argument(k) is sorting the first field (1), starting at the 8th character(.8) and sorting that numerically (n).

Offline

#5 2010-12-15 01:02:49

omgwtfbyobbq
Member
Registered: 2006-07-04
Posts: 226

Re: Ordering the output of locate

Got it! Thanks everyone. smile

Last edited by omgwtfbyobbq (2010-12-15 01:03:03)

Offline

#6 2010-12-25 15:17:59

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Ordering the output of locate

Moved to Workstation User, omgwtfbyobbq please mark your thread solved by prepending it to the title.


ᶘ ᵒᴥᵒᶅ

Offline

Board footer

Powered by FluxBB