Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bash's sort is not complying

Posted on 2014-12-15
4
Medium Priority
?
150 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 85

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 85

Accepted Solution

by:
ozo earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Syslogd is a utility that traps and logs messages sent by running processes. It is configured with the syslog.conf file, which consists of lines containing a pair of fields: "the selector field which specifies the types of messages and priorities to…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

926 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