Avatar of Ralph
RalphFlag for United States of America

asked on 

bash's sort is not complying

I have a file listing all the files on a drive.
The format of the file is:
NumberOfSlashes:FileName:FileSize:FilePath

I got NumberOfSlashes c/o awk.
I want numeric sort on the first column, and general sort on the 4th.


Trying:
cat thefile.txt | sort -t : -k 1,1n -k 4,4

What I get is:
1:  Job Search:135316:/Deskop, Iomega's, Jan 2014
1: Essentials, 2nd Release:59216:/Deskop, Iomega's, Jan 2014
1: PRINTME alias:1941900:/Deskop, Iomega's, Jan 2014
1: Specials alias:519032:/Deskop, Iomega's, Jan 2014
1:.0 Specials alias:519032:/Deskop, Iomega's, Jan 2014
1:.0.localized:0:/Deskop, Iomega's, Jan 2014

As you can see, it's sorting on col 2 for the 2nd criteria, not the 4th.
For -t I've used all of these, no diff.  -t ":"     -t :     -t \:

I did this testing before I looked on the web, and this SHOULD work.
But it doesn't.
==================

I also tried:
cat thefile.txt | sort -t : -k 1,1n -k 4,4d

But even after I changed LC_ALL='C', like it asked, it seems to be eliminating "/" and "-" and who knows what else.  The error message on this is:

sort: string comparison failed: Illegal byte sequence
sort: Set LC_ALL='C' to work around the problem.
sort: The strings compared were `LibraryMailV2AosIMAPrsmithbothellmailmboxDraftsmbox' and `LibraryMailV2AosIMAPrsmithbothellmailmboxExchange \306mbox'.

Never the less, I'm not getting the sort I want.

Any ideas?
Mac OS XShell Scripting

Avatar of undefined
Last Comment
Ralph
Avatar of ozo
ozo
Flag of United States of America image

It looks to me like
1:  Job Search:135316:/Deskop, Iomega's, Jan 2014
1: Essentials, 2nd Release:59216:/Deskop, Iomega's, Jan 2014
1: PRINTME alias:1941900:/Deskop, Iomega's, Jan 2014
1: Specials alias:519032:/Deskop, Iomega's, Jan 2014
1:.0 Specials alias:519032:/Deskop, Iomega's, Jan 2014
1:.0.localized:0:/Deskop, Iomega's, Jan 2014
Are identical in the 1st and 4th columns, so how can you say it is not sorted by them?
Avatar of Ralph
Ralph
Flag of United States of America image

ASKER

This sample output has "/Deskop, Iomega's, Jan 2014" as its first row, supposedly sorted, but I have files at the root, "/", and a DIR or two that start with a space.  They should be at top.  There are a few hundred thousand files in the listing.
Is my `sort` just misbehaving?
I'll look to see if anyone else has mentioned this.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ralph
Ralph
Flag of United States of America image

ASKER

Hi ozo,
Turns out it was my mistake.  When I returned to the problem, before my post, I was sourcing the wrong file, one that I had removed those "missing" files.  
Sort is the working good.
My apologies for wasting your time.
Ralph
Mac OS X
Mac OS X

Mac OS X is the desktop operating system from Apple Inc., found on Macintosh computers. OS X consists of a Mach/BSD-based kernel, operating system interfaces primarily based on FreeBSD and additional frameworks (written in C, C++ and Objective-C providing user interface and application-level services.

15K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo