Solved

bash's sort is not complying

Posted on 2014-12-15
4
116 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In certain circumstances, a Microsoft Office mac application may fail to save a document to a network server, with the following error message: "There has been a network or file permission error. The network connection may be lost." An article at…
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now