Solved

bash's sort is not complying

Posted on 2014-12-15
4
120 Views
Last Modified: 2014-12-16
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?
0
Comment
Question by:Ralph
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40502023
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?
0
 

Author Comment

by:Ralph
ID: 40502138
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.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40502146
The sort command seems to be working for me on sample input I've tried.
Can you show a sample that demonstrates unsorted 1st or 4th columns, along with the same rows in the order that you would have wanted them in?
If we don't have a way to get `sort` to work for you, would doing it with another command be satisfactory?
0
 

Author Comment

by:Ralph
ID: 40503389
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
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Connectivity using SMB Symptoms When connecting to Windows Server shares from a Mac you receive an error similar to "Connection failed because the original item could not be found"Authentication persistently fails to a Windows Server from a Mac wi…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question