Sort in AWK


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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

Code:
L78-60/6:0-1480,195-1480,250-1552,500-1718,750-1862,1000-1985,1250-2102,1500-2235,1750-2406,2000-2600,2250-2763,2500-2907,2750-3086,3000-3310,3250-3496,3500-3661,3750-3789/
L76-37/24:0-1480,71-1480,250-1654,500-1857,750-2003,1000-2144,1250-2388,1500-2636,1750-2780,2000-2884,2250-3129,2500-3372,2750-3547,3000-3675,3250-3773,3500-3851,3750-3928/
L76-28/24:0-1480,54-1480,250-1717,500-1813,750-1964,1000-2101,1250-2234,1500-2399,1750-2556,2000-2684,2250-2843,2500-3034,2750-3171,3000-3300,3250-3409,3500-3585,3750-3794/

I have been using sort -n to sort by 1st field (FS= /) but I can get nothing.

Can anybody help?

Thanks Smilie
Ryan
# 2  
Code:
sort -t '/' -k1,1 myFile

# 3  
Thanks Vgersh99!

I usually use a command line of
Code:
gawk.exe -f filter.awk vel.txt  > filtered_file.txt

How would I use your suggestion in this way? I have played about with the code but only nonsensical results are output to filtered_file.txt

Thanks again

Ryan
# 4  
Quote:
Originally Posted by eknryan
Thanks Vgersh99!

I usually use a command line of
Code:
gawk.exe -f filter.awk vel.txt  > filtered_file.txt

How would I use your suggestion in this way? I have played about with the code but only nonsensical results are output to filtered_file.txt

Thanks again

Ryan
I guess I don't understand why you need to use 'gawk' to do the sorting.
Just use a plain/old 'sort' - no need for gawk/awk.
# 5  
Sorry but I have no idea how to sort without gawk (I also have almost no knowledge of how to use gawk). From what I have read, I thought it would be simple to use. Is it not possible to modify
Code:
sort -t '/' -k1,1 myFile

to run using my command line.

Apologies again. I have learnt alot about gawk since I started but still along way to go. I have no idea about any other unix commands so really just trying to get the grips with AWK for now
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 #634
Difficulty: Easy
The first iPhone featured an internal rechargeable nickel cadmium battery.
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. Homework & Coursework Questions

awk with Grep and Sort

1. The problem statement, all variables and given/known data: Please bare in mind I am a complete novice to this and have very very basic knowledge so please keep any answers as simple as possible and explain in terms I will understand ahha :):) I have a text file of names and test scores... (1 Reply)
Discussion started by: jamesb18
1 Replies

4. Shell Programming and Scripting

how to sort inside awk

Hi guys I have a problem trying to sort output produced with the help of 'Awk'. After "grepping" the pattern out of the file and sorting it, sort command acts a little strange: $ grep -w -n -i "p*cmo" /bb/data/rmt4db.lrl | sort -r 32:P1096CMO 63836 344 passthru 31:P1084CMO 121335 329 passthru... (3 Replies)
Discussion started by: aoussenko
3 Replies

5. Shell Programming and Scripting

awk sort

input file abc1 abc23 abc12 abc15 output abc1 abc12 abc15 abc23 (9 Replies)
Discussion started by: yanglei_fage
9 Replies

6. 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

7. Shell Programming and Scripting

Awk sort and unique

Input file --------- 12:name1:|host1|host1|host2|host1 13:name2:|host1|host1|host2|host3 14:name3: ...... Required output --------------- 12:name1:host1(2)|host1(1) 13:name2:host1(2)|host2(1)|host3(1) 14:name3: where (x) - Count how many times field appears in last column ... (3 Replies)
Discussion started by: greycells
3 Replies

8. Shell Programming and Scripting

Sort and count using AWK

Hi, I've a fixed width file where I need to count the number of patterns from each line between characters 1 to 15 . so can we sort them and get a count for each pattern on the file between 1 to 15 characters. 65795648617522383763831552 410828003265795648 6175223837... (5 Replies)
Discussion started by: rudoraj
5 Replies

9. 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

10. Shell Programming and Scripting

Help, awk sed sort

Hi,everyone: I'm new to shell, and now get trouble with some script: line=`/usr/xpg4/bin/awk '/^(*\|){2}'"$CR"'/ {print $0}' ${TIER4FILE}|grep -v OSNAME=`sed -n ''$LINE'p' $DATALOC/os` sort +1 /tmp/LhasaCRs2 > /tmp/LhasaCRs1 I cannot understand the "{2}" here. My mentor said it... (1 Reply)
Discussion started by: mycoy
1 Replies

Featured Tech Videos