LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   In Laymen's Terms (https://www.linuxquestions.org/questions/linux-newbie-8/in-laymens-terms-733405/)

shoemoodoshaloo 06-16-2009 01:35 PM

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.

TB0ne 06-16-2009 01:46 PM

Quote:

Originally Posted by shoemoodoshaloo (Post 3576195)
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").

pljvaldez 06-16-2009 01:50 PM

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.

steven19782007 06-16-2009 05:25 PM

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.


All times are GMT -5. The time now is 06:18 AM.