I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works
# 1  
Old 11-07-2014
Signal I am learning shell scripting and i would like to understand how sort -k3,3 -k 4,4 short* works

Please help me understand how sort -k3,3 -k 4,4 short* works , is it sorting 3 and 4 th field ? what is the use of specifying 3,3 and 4,4 in sort and what is actually does and i see sort -k3 short* and sort -k3,3 -k 4,4 short* giving the same output.

Sort output attached

Please help
I am learning shell scripting and i would like to understand how  sort -k3,3 -k 4,4 short* works-sortjpg

Last edited by Antony Ankrose; 11-07-2014 at 05:03 PM..
# 2  
Old 11-07-2014
See man pages
Code:
Sort Key Definition Using the -k Flag

       The -k KeyDefinition flag uses the following form:

       -k [ FStart [ .CStart ] ] [ Modifier ] [ , [ FEnd [ .CEnd ] ][ Modifier ] ]

       The sort key includes all characters beginning with the field specified by the FStart variable and the column specified by the CStart variable and ending with the field
       specified by the FEnd variable and the column specified by the CEnd variable. If Fend is not specified, the last character of the line is assumed. If CEnd is not specified
       the last character in the FEnd field is assumed. Any field or column number in the KeyDefinition variable may be omitted. The default values are:
       FStart
            Beginning of the line
       CStart
            First column in the field
       FEnd
            End of the line
       CEnd
            Last column of the field

       If there is any spaces between the fields, sort considers them as separate fields.

       The value of the Modifier variable can be one or more of the letters b, d, f, i, n, or r. The modifiers apply only to the field definition they are attached to and have the

       same effect as the flag of the same letter. The modifier letter b applies only to the end of the field definition to which it is attached.
For example:

       -k 3.2b,3r

       specifies a sort key beginning in the second nonblank column of the third field and extending to the end of the third field, with the sort on this key to be done in reverse
       collation order. If the FStart variable and the CStart variable fall beyond the end of the line or after the FEnd variable and the CEnd variable, then the sort key is
       ignored.

# 3  
Old 11-07-2014
Yes, a "sort short*" will be expanded by the shell, first, into sort followed by the list of files 'short*' expands to. The sort will concatenate them as input. The -k key options say sort by field three through three and then by field four through four, both ascending. Fields are defined by white space unless optioned otherwise, see 'man sort'.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to understand how the line in perl program works as shell commend

I have a file with two line, one is header, the other actual value: TYPCD|ETID2|ETID|LEG ID|PTYP|PTYP SUB|TRD STATUS|CXL REASON|CACT|CACTNM|ENCD|ENC D NM|TRDR|ASDT|TRDT|MTDT|STDT|LS|SECID|SECID TYP|SECNM|PAR|STCC|MARKET PRICE|DIS MARKET PRICE|MARKET PRICE CURRENCY|SRC OF SETTLEMENT... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. UNIX for Beginners Questions & Answers

After Learning Shell Scripting

Will it be good to learn 1) Perl or 2) Ruby first? (3 Replies)
Discussion started by: alvinoo
3 Replies

3. Shell Programming and Scripting

I am learning regular expression in sed,Please help me understand the use curly bracket in sed,

I am learning SED and just following the shell scripting book, i have trouble understanding the grep and sed statement, Question : 1 __________ /opt/oracle/work/antony>cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit... (7 Replies)
Discussion started by: Antony Ankrose
7 Replies

4. Shell Programming and Scripting

Learning curve to understand bash iteration

Hi Folks, I know on one side there is script and on another side there is smart script. I am able to achieve what I got but thought there has to be a code which doesn't require multiple lines. So if you guys can help me out than it will be awesome. Also I wrote in cshell but if can get both the... (4 Replies)
Discussion started by: dixits
4 Replies

5. Shell Programming and Scripting

Learning Scripting

Hi All, I am facing an issue. I need your advise. I want to take my unix skills to the next level. I want to verse in scripting now. I got some understanding of programming. I did a little bit of C++, Assembly in College. I got some basics in perl. I am wondering if It would be best to... (3 Replies)
Discussion started by: Pouchie1
3 Replies

6. Shell Programming and Scripting

Shell scripting book learning.

Hi Which is the most useful shell scripting book. Planning to learn shell scripting.Thanks in advance. (1 Reply)
Discussion started by: arunvellanki
1 Replies

7. UNIX for Dummies Questions & Answers

Book for Learning unix shell scripting reall good

Hi guys I want o learn and understand shell scripting real good, Ive got already some background Due to the fact that there is ton of books with these theme, can you recommend me some good book with with examples explanations, pls no theoretical books :D Thxs (3 Replies)
Discussion started by: kl1ngac1k
3 Replies

8. Shell Programming and Scripting

Suggested Books for Learning Shell scripting

Hi, I had completed RHCE and i am interested to learn shell scripting. Request you to please let me know which book is best for learning shell scripting or any online website. Thanks & Regards arun (2 Replies)
Discussion started by: Arun.Kakarla
2 Replies

9. Shell Programming and Scripting

Understand Bash scripting encryption

Dear all, I have been working with Linux for quite few years but never required to learn Bash and Linux really dep doan. I want to learn bash I bought books and Have been reading on the Internet but I cannot find my answers, maybe I am blind. For example: What does this means? # for i in... (4 Replies)
Discussion started by: renpippa
4 Replies

10. Shell Programming and Scripting

Learning Shell Scripting

I'm new to UNIX and I want to learn Shell Scripting. I want a web site that has Shell Scripting tutorials. Any suggesstions?.? (3 Replies)
Discussion started by: liveapple2000
3 Replies
Login or Register to Ask a Question