Sorting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting
# 8  
Old 05-19-2010
vgersh99,

Are the first two lines

nawk -f ernst.awk inputFile

ernst.awk:


part of the code. If yes, what is the ernst.awk?

If not, where do I enter the input file? I am trying to make sense of the code.

Thanks!
# 9  
Old 05-19-2010
the block of code is the content of ernst.awk file.
Your input to the script is assumed to be in file 'inputFile'.
The calling sequence is:
nawk -f ernst.awk inputFile
# 10  
Old 05-19-2010
Above code "nawk -f ernst.awk inputFile", I got output with 5 groups.

Assume your code are sorted by descending order in each group, here is my code, only get 3 groups output, and seems it is correct. Please confirm.

Code:
awk 'BEGIN{RS="";FS="=";ORS="\n\n"} 
       {if ($NF > $(NF-2) || $NF > $(NF-4) || $(NF-2) > $(NF-4)) print }' urfile


230.3=146
230.2=147
230.1=148

100.6=176
100.5=172
100.4=168
100.3=20
100.2=12
100.1=16

117.3=24
117.2=82
117.1=79

# 11  
Old 05-20-2010
rdcwayx:

Interestingly enough, your script works fine with the sample that I published (short file) but does not work for a larger file, my database for example. When I use your script for my database which contains hundreds of goupings, I have the following error message:
Code:
awk: record `1  .6=
1  .5=
1 ...' too long



---------- Post updated at 08:35 AM ---------- Previous update was at 08:23 AM ----------

vgersh99:


I do not get an error message when I run your script with my database, but the output file is empty. I do not get any data which is wrong because I know for sure some of the goupings met the conditions that I listed.

Last edited by Scott; 05-20-2010 at 09:25 AM.. Reason: Code tags, please...
# 12  
Old 05-20-2010
Ernst,
what OS are you on?
It was as expected with your sample file using 'nawk' on Sun's Solaris.
# 13  
Old 05-20-2010
Here's a Perl solution -

Code:
$
$
$ # display the contents of the input file
$ cat input.dat
1.6=176
1.5=172
1.4=168
1.3=14
1.2=13
1.1=12
 
230.3=146
230.2=147
230.1=148
 
3.3=20
3.2=19
3.1=18
 
5.6=166
5.5=122
5.4=160
5.3=103
5.2=102
5.1=100
 
100.6=176
100.5=172
100.4=168
100.3=20
100.2=12
100.1=16
 
117.3=24
117.2=82
117.1=79
$
$
$ # Process the data with a Perl one-liner
$ perl -lne 'chomp;
           if (/^\s*$/) {
             if ($x>$y or $x>$z or $y>$z) {print foreach (@a); print}
             @a=(); $x=$y=$z="";
           } else {
             push @a,$_;
             if (/^\d+\.1=(.*)$/) {$x = $1}
             elsif (/^\d+\.2=(.*)$/) {$y = $1}
             elsif (/^\d+\.3=(.*)$/) {$z = $1}
           }
           END {if ($x>$y or $x>$z or $y>$z) {print foreach (@a); print}}
          ' input.dat
230.3=146
230.2=147
230.1=148
 
100.6=176
100.5=172
100.4=168
100.3=20
100.2=12
100.1=16
 
117.3=24
117.2=82
117.1=79
 
$
$

tyler_durden
# 14  
Old 05-20-2010
I am using:

Code:
FMLISHELL=/sbin/sh
SHELL=/sbin/sh

Durden:
You are right. your scripts work fine for the small sample I provided you with. However, they do not work for my huge file.
With my huge file, I do not get an output file. Whenever I cat the output, I do not get any data.
I did not get an error message either.

Below is my input file:
Code:
1  .6=   
1  .5=   
1  .4=   
1  .3=12 
1  .2=348
1  .1=180
10 .6=   
10 .5=   
10 .4=   
10 .3=360
10 .2=192
10 .1=24 
100.6=   
100.5=   
100.4=   
100.3=364
100.2=196
100.1=28 
101.6=   
101.5=   
101.4=   
101.3=464
101.2=296
101.1=128
102.6=   
102.5=   
102.4=   
102.3=444
...
...

Try your scripts and let me know whether or not it works for you.

Thanks!

Last edited by Scott; 05-21-2010 at 11:05 AM.. Reason: Final warning to add code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sorting

Hii guys, I need to sort my file and remove duplicates before writing to another file. The first line in the file are column names. I dont want this line to be sorted and should always be the first line in the output. sort -u file.txt > file1.txt. is the command that i am using... (4 Replies)
Discussion started by: just4u_sharath
4 Replies

2. Shell Programming and Scripting

sorting help

Hi, Please i need help in writing an 'awk' script in sorting the following data; traceroute6 to 2001:1ba0:2a0:5965:0:30:24:1 (2001:1ba0:2a0:5965:0:30:24:1) from 2001:418:1::62, 64 hops max, 16 byte packets 1 2001:418:1::4 0.342 ms 2 2001:418:1::1 0.630 ms 3 2001:504:16::1b1b 0.393 ms 4... (6 Replies)
Discussion started by: sam127
6 Replies

3. Shell Programming and Scripting

sorting

Hi all, Does anyone can help me the following question? I would like to write an AWK script. In the following input file, each number in "start" is paired with numbers in column "end". No Start End A 22,222,33,22,1233,3232,44 555,333,222,55,1235,3235,66... (7 Replies)
Discussion started by: phoeberunner
7 Replies

4. Shell Programming and Scripting

Sorting HELP

Hi, I have posted related topic but as i continue the research I find more need to sort the data. AS(2607:f278:4101:11:dead:beef:f00f:f), AS786 AS6453 AS7575 AS7922 AS(2607:f2e0:f:1db::16), AS786 AS3257 AS36252 AS786 AS3257 AS36252 AS(2607:f2f8:1700::2), AS786 AS6939 AS25795 ... (6 Replies)
Discussion started by: sam127
6 Replies

5. UNIX for Advanced & Expert Users

HELP on sorting

hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this; 192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible... (1 Reply)
Discussion started by: sam127
1 Replies

6. UNIX for Dummies Questions & Answers

HELP on sorting

hi everyone, I am kind of new to this forum. I need help in sorting this data out accordingly, I am actually doing a traceroute application and wants my AS path displayed in front of my address like this; 192.168.1.1 AS28513 AS65534 AS5089 AS5089 .... till the last AS number and if possible... (1 Reply)
Discussion started by: sam127
1 Replies

7. Homework & Coursework Questions

Sorting help

i have list of files: Wang De Wong CVPR 09.pdf Yaacob AFGR 99 Second edition.pdf Shimon CVPR 01.pdf Den CCC 97 long one.pdf Ronald De Bour CSPP 04.pdf ..... how can i sort this directory so the output will be in the next format: <year>\t<conference/journal>\t<author list> - t is tab (its... (1 Reply)
Discussion started by: nirnir26
1 Replies

8. UNIX for Dummies Questions & Answers

Sorting help

i have list of files: Wang De Wong CVPR 09.pdf Yaacob AFGR 99 Second edition.pdf Shimon CVPR 01.pdf Den CCC 97 long one.pdf Ronald De Bour CSPP 04.pdf ..... how can i sort this directory so the output will be in the next format: <year>\t<conference/journal>\t<author list> - t is tab (its... (1 Reply)
Discussion started by: nirnir26
1 Replies

9. UNIX for Dummies Questions & Answers

Sorting help

how can i sort the next list just by look at the numbers (ignore letters) example: abc123 dff4f aaa2aa bbbb55555bb output: aaa2aa dff4f abc123 bbbb55555bb (1 Reply)
Discussion started by: nirnir26
1 Replies

10. Shell Programming and Scripting

Need immediate help with sorting!!!

hey, I have a file that looks smthng like this: /*--- abcd_0050 ---*/ asdfjk adsfkja lkjljgafsd /*---abcd_0005 ---*/ lkjkljbfkgj ldfksjgf dfkgfjb /*-- abcd_0055--*/ klhfdghd dflkjgd jfdg I would like it to be sorted so that it looks like this: /*---abcd_0005 ---*/ lkjkljbfkgj (9 Replies)
Discussion started by: sasuke_uchiha
9 Replies
Login or Register to Ask a Question