Sponsored Content
Full Discussion: Sort table ignoring header
Top Forums UNIX for Beginners Questions & Answers Sort table ignoring header Post 303046346 by shanul karim on Friday 1st of May 2020 01:32:42 PM
Old 05-01-2020
Sort table ignoring header

Dear experts,


Need help in order to find out way to sort table ignoring header.




Quote:
awk 'BEGIN{print ("NAME DATE,TIME CNT1 CNT2 CNT3 CNT4 SR1 SR2 SR3 ")}function printValues(){if (Values){print S, Date, Value["NSMSSMRLTOT"],Value["NSMSSRSUCC"],Value["NSMSCMTOT"],Value["NSMSCMRSUCC"],(Value["NSMSSRSUCC"]/Value["NSMSSMRLTOT"])*100,(Value["NSMSCMRSUCC"]/Value["NSMSSMRLTOT"])*100,(Value["NSMSCMRSUCC"]/Value["NSMSCMTOT"])*100;}delete Value;}$1~/^BC/{S=$1}$7=="(OK)"{printValues();Date = $2 " " $3 " " $4;S;next;}$1+0{Value[$3] = $2;Values++;next;}END{ printValues()}' SHMSGSERV24_2 | column -t |sort -n -k 4

Here I tried the sort option to ignoring header as



Code:
awk 'BEGIN{print ("NAME DATE,TIME CNT1 CNT2 CNT3 CNT4 SR1 SR2 SR3 ")}function printValues(){if (Values){print  S, Date,   Value["NSMSSMRLTOT"],Value["NSMSSRSUCC"],Value["NSMSCMTOT"],Value["NSMSCMRSUCC"],(Value["NSMSSRSUCC"]/Value["NSMSSMRLTOT"])*100,(Value["NSMSCMRSUCC"]/Value["NSMSSMRLTOT"])*100,(Value["NSMSCMRSUCC"]/Value["NSMSCMTOT"])*100;}delete Value;}$1~/^BC/{S=$1}$7=="(OK)"{printValues();Date = $2 " " $3 " " $4;S;next;}$1+0{Value[$3] = $2;Values++;next;}END{ printValues()}' SHMSGSERV24_2 | column -t |{head -n 1;sort -n -k 4;}


But this option deleting few lines in between. Any other suggestion.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

unix sort according to a header line

Hi, I have a file with a header line, followed by some contents. How can I sort the file according to header lines? eg. /* abcd_005*/ a bc /* abcd_001*/ d e /* abcd_002*/ x y desired output: /*abcd_001*/ (0 Replies)
Discussion started by: neil.0412
0 Replies

2. Shell Programming and Scripting

Simple sort with header

Hi, Please help with this problem. Somehow does not work for me. test.txt CHR SNP BP A1 C_A C_U A2 CHISQ P OR 19 rs10401969 19268718 C 222 890 T 0.03462 0.8524 0.9857 1 rs10873889 ... (4 Replies)
Discussion started by: genehunter
4 Replies

3. Linux

Top header says 50% free, but table shows 100% used

Hi, Can anyone explain this? top - 04:21:04 up 23 days, 2:35, 1 user, load average: 0.02, 0.02, 0.00 Tasks: 37 total, 1 running, 36 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 524288k total, 253084k used,... (1 Reply)
Discussion started by: varontron
1 Replies

4. Shell Programming and Scripting

How to Add Table with Header for Shell Output

I have a Script that generates 3 columns of the result. The line script is /usr/xpg4/bin/awk -F' ' '{print $1 /t $2}' File_Name | awk -F'>' '{print $2}' | cut -d'<' -f1 | sort -rn | uniq -c The output of the Command is : Code.500 4 Input Error Code.404 ... (4 Replies)
Discussion started by: raghunsi
4 Replies

5. UNIX for Dummies Questions & Answers

Merge all csv files in one folder considering only 1 header row and ignoring header of all others

Friends, I need help with the following in UNIX. Merge all csv files in one folder considering only 1 header row and ignoring header of all other files. FYI - All files are in same format and contains same headers. Thank you (4 Replies)
Discussion started by: Shiny_Roy
4 Replies

6. UNIX for Dummies Questions & Answers

Sort a tab file with header.

How to sort a tab delimited file first on col1 and then on col2. Also I need to keep the header intact. file.txt val1 val2 val3 val4 a b c d m n o p e f g h i j k l ... (3 Replies)
Discussion started by: mary271
3 Replies

7. Shell Programming and Scripting

Replace a column with a value by ignoring the header lines

i have a file in the gz format , the content of the file is as follow. gzcat f1.gz # 1.name # 2.location # 3.age # 4.dob . . . . . . . . . # 43.hobbies < Aravind,33,chennai,09091980, , , , , , , surfing> (5 Replies)
Discussion started by: aravindj80
5 Replies

8. UNIX for Dummies Questions & Answers

Sort a las file keep the header as it is

I have several las files with a header and each file start Version and text and before the data starts end up with ~Ascii, then the numbers starts: ------------------------------------------------------------------------- Code: ~Version .....text.... ~Ascii 2 abc 230 1 name 1 abc ... (1 Reply)
Discussion started by: tk2000
1 Replies

9. UNIX for Dummies Questions & Answers

Sort a las file keep the header as it is

I have several las files with a header and each file start Version and text and before the data starts end up with ~Ascii, then the numbers starts: ------------------------------------------------------------------------- ~Version .....text.... ~Ascii 2 abc 230 1 name 1 abc 400 1... (17 Replies)
Discussion started by: tk2000
17 Replies

10. Shell Programming and Scripting

Sort without Header and Trailer

Hi , My UNIX system is SUN Solaris. I am trying to do a simple thing as described below. I have a PIPE delimited file that has header and trailer. So the file is something like below: Test1.txt looks like something below: field_data1|field_data2|and some more data --Header ... (5 Replies)
Discussion started by: Saanvi1
5 Replies
sort(3pm)						 Perl Programmers Reference Guide						 sort(3pm)

NAME
sort - perl pragma to control sort() behaviour SYNOPSIS
use sort 'stable'; # guarantee stability use sort '_quicksort'; # use a quicksort algorithm use sort '_mergesort'; # use a mergesort algorithm use sort 'defaults'; # revert to default behavior no sort 'stable'; # stability not important use sort '_qsort'; # alias for quicksort my $current; BEGIN { $current = sort::current(); # identify prevailing algorithm } DESCRIPTION
With the "sort" pragma you can control the behaviour of the builtin "sort()" function. In Perl versions 5.6 and earlier the quicksort algorithm was used to implement "sort()", but in Perl 5.8 a mergesort algorithm was also made available, mainly to guarantee worst case O(N log N) behaviour: the worst case of quicksort is O(N**2). In Perl 5.8 and later, quicksort defends against quadratic behaviour by shuffling large arrays before sorting. A stable sort means that for records that compare equal, the original input ordering is preserved. Mergesort is stable, quicksort is not. Stability will matter only if elements that compare equal can be distinguished in some other way. That means that simple numerical and lexical sorts do not profit from stability, since equal elements are indistinguishable. However, with a comparison such as { substr($a, 0, 3) cmp substr($b, 0, 3) } stability might matter because elements that compare equal on the first 3 characters may be distinguished based on subsequent characters. In Perl 5.8 and later, quicksort can be stabilized, but doing so will add overhead, so it should only be done if it matters. The best algorithm depends on many things. On average, mergesort does fewer comparisons than quicksort, so it may be better when complicated comparison routines are used. Mergesort also takes advantage of pre-existing order, so it would be favored for using "sort()" to merge several sorted arrays. On the other hand, quicksort is often faster for small arrays, and on arrays of a few distinct values, repeated many times. You can force the choice of algorithm with this pragma, but this feels heavy-handed, so the subpragmas beginning with a "_" may not persist beyond Perl 5.8. The default algorithm is mergesort, which will be stable even if you do not explicitly demand it. But the stability of the default sort is a side-effect that could change in later versions. If stability is important, be sure to say so with a use sort 'stable'; The "no sort" pragma doesn't forbid what follows, it just leaves the choice open. Thus, after no sort qw(_mergesort stable); a mergesort, which happens to be stable, will be employed anyway. Note that no sort "_quicksort"; no sort "_mergesort"; have exactly the same effect, leaving the choice of sort algorithm open. CAVEATS
As of Perl 5.10, this pragma is lexically scoped and takes effect at compile time. In earlier versions its effect was global and took effect at run-time; the documentation suggested using "eval()" to change the behaviour: { eval 'use sort qw(defaults _quicksort)'; # force quicksort eval 'no sort "stable"'; # stability not wanted print sort::current . " "; @a = sort @b; eval 'use sort "defaults"'; # clean up, for others } { eval 'use sort qw(defaults stable)'; # force stability print sort::current . " "; @c = sort @d; eval 'use sort "defaults"'; # clean up, for others } Such code no longer has the desired effect, for two reasons. Firstly, the use of "eval()" means that the sorting algorithm is not changed until runtime, by which time it's too late to have any effect. Secondly, "sort::current" is also called at run-time, when in fact the compile-time value of "sort::current" is the one that matters. So now this code would be written: { use sort qw(defaults _quicksort); # force quicksort no sort "stable"; # stability not wanted my $current; BEGIN { $current = sort::current; } print "$current "; @a = sort @b; # Pragmas go out of scope at the end of the block } { use sort qw(defaults stable); # force stability my $current; BEGIN { $current = sort::current; } print "$current "; @c = sort @d; } perl v5.18.2 2013-11-04 sort(3pm)
All times are GMT -4. The time now is 07:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy