ramman
July 10, 2012, 2:11pm
1
Hello all,
I am using printf to print the sorted o/p in my script.I am trying to sort in following way but doesn't work.
printf "%13s %2s UDP %15s:%s Program %4s HD: %23s HD: %23s %10s %s %s %3s days %3s hours\n" $encoder $i "${ipaddr[$i]}" ${portno[$i]} ${progno[$i]} ${inres[$i]} ${outres[$i]} ${inrate} ${enable} ${run[$i]} ${edate1[$i]} ${etime1[$i]} | sort -k 13,13n -k 14,14n -k 15,15n -k 16,16n -k 17,17n
I am trying to sort 13,14,15,16 and 17th column of the o/p sorted.
Is this the right method or something else can be done?
Thank you.
zaxxon
July 10, 2012, 2:50pm
2
You kidding us? Why in the world don't you just try it out?
That's what I do not understand.
After you try it out for yourself, as zaxxon suggests, if it doesn't work as expected, at the very least provide the input data, the output your code generated, and the output you expected.
Regards,
Alister
ramman
July 10, 2012, 7:50pm
4
hey guys i did try it out and it didn't work that's why i posted,let me make my question more clear.
I execute the following code
for i in {1..12};do printf "%s %s\n" "${edate1[$i]}" "${etime1[$i]}"
(I retrieve the values of edate1 and etime1 from my database and store it in an array which works fine.)
I receive the o/p as:
97 16
97 16
97 12
107 16
97 16
97 16
97 16
97 16
97 16
97 16
97 16
100 15
I want to sort both these columns using the sort command.Please help me out.
Thanks.
---------- Post updated at 04:50 PM ---------- Previous update was at 04:43 PM ----------
Expected O/P:
107 16
100 15
97 16
97 16
97 16
97 16
97 16
97 16
97 16
97 16
97 16
97 12
zaxxon
July 11, 2012, 2:23am
5
$sort -rn -k1.1 -k2.2 infile
107 16
100 15
97 16
97 16
97 16
97 16
97 16
97 16
97 16
97 16
97 16
97 12
1 Like