Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sort in cygwin

Posted on 2009-04-24
3
Medium Priority
?
633 Views
Last Modified: 2013-11-15
A very simple example that I don't understand.

A file test.txt contains two records:

RECORD1XYZ|FIELD2
RECORD1|FIELD2

I use the following command to sort:

sort -t"|" test.txt

and the result is:

RECORD1XYZ|FIELD2
RECORD1|FIELD2

how come?

0
Comment
Question by:goph9998
  • 2
3 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 2000 total points
ID: 24227642
If you don't specify the key to sort on, the whole line is compared.

sort -t"|" -k1,1

info sort

has a good description of it.
0
 

Author Comment

by:goph9998
ID: 24228173
if I change "|" to ":" it works
0
 
LVL 58

Assisted Solution

by:amit_g
amit_g earned 2000 total points
ID: 24228474
That is because it is sorting the while line. The field separator doesn't matter.

When you compare

RECORD1XYZ|FIELD2
RECORD1|FIELD2

the first characters that are different is X and | and between those X < |

but when you compare

RECORD1XYZ:FIELD2
RECORD1:FIELD2

the first character that are different are X and : and between those X > :

ASCII(':') - 58
ASCII('X') - 88
ASCII('|') - 124
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Today as you open your Outlook, you witness an error message: “Outlook is using an old copy of your Outlook Data File…”. Probably, Outlook is accessing an old OST file.
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

805 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