awk sort


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk sort
# 1  
awk sort

input file
Code:
abc1
abc23
abc12
abc15

output

Code:
abc1
abc12
abc15
abc23

# 2  
Why not simply
sort
# 3  
why do you need awk to sort ?

you can simply use the sort command

Code:
$ sort input.txt
abc1
abc12
abc15
abc23

# 4  
Quote:
Originally Posted by itkamaraj
why do you need awk to sort ?

you can simply use the sort command

Code:
$ sort input.txt
abc1
abc12
abc15
abc23


actually it does NOT work

you can try

Code:
abc1
abc12
abc15
abc2
abc23

---------- Post updated at 08:06 AM ---------- Previous update was at 08:06 AM ----------

Quote:
Originally Posted by joeyg
Why not simply
sort



actually it does NOT work

you can try

Code:
abc1
abc12
abc15
abc2
abc23

# 5  
Code:
sort -k 1.4n infile

You should start checking the man page for commands.
# 6  
Well, you just changed the sample!

What are you trying to have happen?
# 7  
Quote:
Originally Posted by zaxxon
Code:
sort -k 1.4n infile

You should start checking the man page for commands.

I have man sort it says

Code:
       -k, --key=POS1[,POS2]
              start a key at POS1 (origin 1), end it at POS2 (default end of line)

BUT, I don't understand the "1" "." "4", how did you get them?

Last edited by Scott; 08-20-2012 at 09:50 PM.. Reason: Code tags
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #200
Difficulty: Easy
Larry Wall began work on Perl in 1977.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk pipe to sort

In the below awk to add a sort by smallest to largest should it be added after the END? Thank you :). BEGIN { FS="*" } # Read search terms from file1 into 's' FNR==NR { s next } { # Check if $5 matches one of the search terms for(i in s) { if($5 ~ i) { ... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Sort by first row - awk

how can i sort the table based on first row? thanks in advance input name d b c a l l1 l2 l3 l4 l1 1 2 3 4 l2 2 2 2 1 l3 1 1 2 2ouput name a b c d l1 l4 ... (4 Replies)
Discussion started by: quincyjones
4 Replies

3. Shell Programming and Scripting

Sort String using awk

Hi, I need help to sort string using awk. I don't want to use sed or perl as I want to add this functionality in my existing awk script Basically I have a variable in AWK which is string with comma separated value. I want to sort that string before using that variable in further processing for... (10 Replies)
Discussion started by: rocky.community
10 Replies

4. Shell Programming and Scripting

Need help on horizontal sort with AWK

dear friends.. i have data : 20130603;ABCD;ABCD1;14030;51271;0.000;0.000;21.000 20130603;ABCD;ABCD2;14030;51272;4853.000;53591.000;40539.000 20130603;ABCD;ABCD3;14030;51273;38024.000;385068.000;396424.000 20130603;ABCD;EFGH1;14030;51334;285879.000;563964.000;141780.000... (4 Replies)
Discussion started by: buncit8
4 Replies

5. Shell Programming and Scripting

awk array sort

I have a file as below Input File: 5/11/2012, dir1, 134 5/11/2012, dir2, 2341 5/11/2012, dir3, 2134 5/11/2012, dir4, 2334 5/12/2012, dir1, 234 5/12/2012, dir2, 2341 5/12/2012, dir3, 2334 5/13/2012, dir1, 234 5/13/2012, dir2, 2341 5/13/2012, dir3, 2334 5/13/2012, dir4, 21134 Now... (6 Replies)
Discussion started by: chakrapani
6 Replies

6. Shell Programming and Scripting

match and sort using awk

Hello, Is it possible to do match and sort the data from two fields in a file using awk? Like for example: input apple cat in rat out sky cat pen rat ball sky cpu pen linux ball unix cpu paper linux phone unix paper phone (8 Replies)
Discussion started by: avatar_007
8 Replies

7. Shell Programming and Scripting

Sort in AWK

Hi, I usually use Access to sort data however for some reason its not working. Our systems guys and myself cannot figure it out so ive tried to use AWK to do the sorting. The file is made up of single lines in the format ... (4 Replies)
Discussion started by: eknryan
4 Replies

8. Homework & Coursework Questions

awk sort help

1. The problem statement, all variables and given/known data: I dont know what I do wrong, I am trying to create shell programming database: I have this command first: && > $fname ... echo $Name:$Surname:$Agency:$Tel:$Ref: >> $fname then I have echo " Name Surname Agency Tel... (2 Replies)
Discussion started by: jeht
2 Replies

9. Shell Programming and Scripting

how to use awk to sort this problem out

there has several numbers which are:1,2,3,45,6,7,8,9,0,10,34,34,54,122,6756,54,87,99,2,1,45; how to write a shell script orts the above numbers into descending order and puts them into and arrray and also find and prints the minimum and maximum of those numbers, and finds and prints the average... (4 Replies)
Discussion started by: sonicstage
4 Replies

10. Shell Programming and Scripting

Using sort with awk script

I have a file with four fields and an awk script that strips out one field displaying the remaining three. I have added headings for each of these fields such as Player - Year - RBIs then below it comes the data. What I am trying to do is sort the RBIs field in my script from most to least at the... (9 Replies)
Discussion started by: Trellot
9 Replies

Featured Tech Videos