Solved

bash's sort is not complying

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux Scripting 3 143
Favorites from Mac Safari to Chrome? 4 38
A beginner asks: Which macos postgreSQL client? 5 41
Unable to print PDF document on Mac laptop 6 21
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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 …
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…

791 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