LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2009, 02:35 PM   #1
shoemoodoshaloo
LQ Newbie
 
Registered: Jun 2009
Posts: 18

Rep: Reputation: 0
In Laymen's Terms


I am reading over a program that was written by a former student, and it has this command:

tr -s ' ' < oldfile | sort -n -k2 > newfile

Which takes a data file and puts it in numerical order, according to the values in the second column, from lowest to greatest. I understand the piping feature, but am wondering if anyone can tell me what the meaning is of:

tr -s ''

and

-k2 (I assume this means column 2. Does it mean anything else?)

Thanks.
 
Old 06-16-2009, 02:46 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,933

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by shoemoodoshaloo View Post
I am reading over a program that was written by a former student, and it has this command:

tr -s ' ' < oldfile | sort -n -k2 > newfile

Which takes a data file and puts it in numerical order, according to the values in the second column, from lowest to greatest. I understand the piping feature, but am wondering if anyone can tell me what the meaning is of:

tr -s ''

and

-k2 (I assume this means column 2. Does it mean anything else?)

Thanks.
Check out the man page for tr ("man tr" at a prompt). The "tr -s" invokes the "squeeze" function (replace multiple characters with a single occurance). The "-k2" in the above example, is an option to the sort command, along with the "-n" ("man sort").
 
Old 06-16-2009, 02:50 PM   #3
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 271Reputation: 271Reputation: 271
The first part says to convert each double instance of a space (the blank space is included in the two single quotes) to a single space. See man tr.

No idea on the second one.
 
Old 06-16-2009, 06:25 PM   #4
steven19782007
LQ Newbie
 
Registered: Jan 2007
Location: Merseyside
Distribution: Ubuntu 9.04
Posts: 15

Rep: Reputation: 1
sort options

The -k2 part means sort by the second field in the line. It sorts starting at the beginning of the 2nd field and continues to the end of the line, if you were to change it to -k2,2, the sort would start at the first character of field 2 and end at the last character of field 2.

The -n option means that the sort is done comparing integers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with the terms linuxhr123 Linux - Newbie 1 12-06-2007 11:45 AM
Terms RodimusProblem General 6 01-20-2005 09:43 AM
Pronunciation of a few terms phil.d.g General 1 01-02-2005 07:50 PM
Linux Terms jesman_dell Linux - Newbie 8 01-08-2004 04:44 PM
linux terms blistfix Linux - Newbie 2 06-24-2001 02:36 AM


All times are GMT -5. The time now is 08:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration