LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 01: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, 01:46 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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, 01:50 PM   #3
pljvaldez
LQ Guru
 
Registered: Dec 2005
Location: Somewhere on the String
Distribution: Debian Wheezy (x86)
Posts: 6,094

Rep: Reputation: 281Reputation: 281Reputation: 281
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, 05: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



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 10:45 AM
Terms RodimusProblem General 6 01-20-2005 08:43 AM
Pronunciation of a few terms phil.d.g General 1 01-02-2005 06:50 PM
Linux Terms jesman_dell Linux - Newbie 8 01-08-2004 03:44 PM
linux terms blistfix Linux - Newbie 2 06-24-2001 01:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:14 PM.

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
Open Source Consulting | Domain Registration