Solved

Clarification in sort command in Unix

Posted on 2014-03-10
5
386 Views
Last Modified: 2014-05-06
Can anyone explain what are the actions performed by the below sort commands.

sort -t'|' tmp1 -o tmp2
sort -t'|' -k 4,4n -o current.data tmp2

Open in new window

0
Comment
Question by:gaugeta
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 39919718
First one does a alpha-numeric sort of the tmp1 file using the pipe (|) symbol as the field separator and outputs the results to the file tmp2.

The second one does a numeric sort of the 4th field (pipe delimited) of tmp2 and outputs the result to current.data
0
 

Author Comment

by:gaugeta
ID: 39919747
@Tintin : Thanks for the reply.

So does the first command does a generic sort of the entire file in ascending order.

I was wondering if this syntax would suffice : sort -t'|' -k 4n -o current.data tmp2 , in the above command why do we need an extra 4,4n
0
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 39919763
>So does the first command does a generic sort of the entire file in ascending order.

Correct.

-k 4n and -k4,4n are different.

-k 4n  means sort based on the fourth field to the end of the line.

-k 4,4n means sorted based on the fourth field only.
0
 

Author Comment

by:gaugeta
ID: 39919771
So if I have 10 fields separated by "|" does sort -t'|' -k 4n -o current.data tmp2  sort the file including colums from the 4th-10th.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39922201
Correct.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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