awk: last occurance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk: last occurance
# 15  
Old 01-03-2007
Hi anbu23,

Thanks for this. I'm not on Solaris so I've made a minor change (at least that's why I think I had to change it...)

Code:
 /test/nigelp> awk -F, -f alg_awk_2 test.alg | sort -t, +3n      
TEST:HOME,01010515,20061230204800,,0794,10,DIAG;                    
TEST:HOME,0102050A,20061230205838,,1094,10,DIAG;                    
TEST:HOME,01020518,20061230213158,,2844,10,DIAG;                    
TEST:HOME,01020502,20061230185622,,7397,10,DIAG;                    
TEST:HOME,01010513,20061230195958,,8721,10,DIAG;                    
TEST:HOME,0102051A,20061230201042,,8998,10,DIAG;                    
TEST:HOME,01020514,20061230202733,,9620,10,DIAG;

Interestingly it's not sorting field 3 as I'd expect - it's a date time field which I would've thought should sort numerically. Am I doing something wrong?

Also I'd really like the sort to be contained within the awk to keep things elegant. Is there a way of doing this?

Many thanks, p.
# 16  
Old 01-03-2007
I've just spotted my sort command error: +3n isn't field 3 +2n is actually the 3rd field reference...

I'd still like to contain the sort within the awk if possible, anyone know how I can do this?

This is the awk that I'm using:

Code:
{                       
   lines[$2] = $0       
}                       
END {                   
    for (i in lines)    
        print lines[i]  
}

Thanks again, p.
# 17  
Old 01-03-2007
Code:
 /test/nigelp> awk -F, -f alg_awk_2 test.alg | sort -t, +3n

+3 means numeric key beginning at the start of fourth field
# 18  
Old 01-03-2007
Quote:
Originally Posted by shereenmotor
Reborg,

Whats the timelimit for the edit by the way? I think 30 minutes?
It's a setting which can only be set/viewed from the admin control panel, so I guess you'd have to ask Perderabo or Neo, however the default in Vb for 3.0.11 appears to be 2 minutes so I'm guessing it's the same here.

The time limit for actually being able to edit a post is usually forever.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract only first occurance

Hi All, From the below file. I need to get only the first occurrence and print. I tried to do it in separate grep not coming as expected Original file 11001;1213;304;;;;;;;111020677.64;;;;;;;;;;;;;;;;;;;;;;;;;; 11001;1214;304;;;;;;;102376462.96;;;;;;;;;;;;;;;;;;;;;;;;;;... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies

2. Shell Programming and Scripting

Trying to grep for '--' occurance

Hello Im trying to grep for a string in grub.conf . I've used the -F option since its a long string, but when i execute, i run into errors. Script and output below. GRUBPASSWD="password --md5 xyz" if grep -Fxq $GRUBPASSWD /etc/grub.conf then . . output: grep: unrecognized option... (5 Replies)
Discussion started by: bludhemn
5 Replies

3. Shell Programming and Scripting

awk to replace second occurance

#original file . . ~ ~ Index=2 xxx replace #dont replace 1st occurance yyy Index=2 xxx replace #substitue replace with "REPLACE" yyy Index=2 xxx replace #substitue replace with "REPLACE" yyy Index=3 xxx replace (3 Replies)
Discussion started by: cjjoy
3 Replies

4. Shell Programming and Scripting

First occurance

A PERL script that prints just the first occurrence of a string in a file and immediately exits (the string and the filename are the first and the second command line arguments; I used filehandle to open an input file). (1 Reply)
Discussion started by: aadi_uni
1 Replies

5. Shell Programming and Scripting

Count the Consecutive Occurance of "X" in awk

Hi All, I have a data as follow: 0 0 0 X X 0 X X X 0 X 0 0 X 0 0 (16 Replies)
Discussion started by: nica
16 Replies

6. Shell Programming and Scripting

How can I match lines with just one occurance of a string in awk?

Hi, I'm trying to match records using awk which contain only one occurance of my string, I know how to match one or more (+) but matching only one is eluding me without developing some convoluted bit of code. I was hoping there would be some simple pattern matching thing similar to '+' but... (9 Replies)
Discussion started by: jonathanm
9 Replies

7. Shell Programming and Scripting

Split on last occurance

I want to call a script like this: ./somescript some-thing.knows.what.ending Inside the script it needs to split at last .(period) so I can: a=some-thing.knows.what b=ending I know I can do it in perl but im still learing awk and sed. Thanks (3 Replies)
Discussion started by: Ikon
3 Replies

8. Shell Programming and Scripting

How to insert values in 1st occurance out of two occurance in a file

Hi I have a file which contains the following two lines which are same But I would like to insert the value=8.8.8.8 in the 1st occurance line and value=9.9.9.9 in the 2nd occurance line. <parameter name="TestIp1" value=""> <parameter name="TestIp1" value=""> Please suggest (1 Reply)
Discussion started by: madhusmita
1 Replies

9. Shell Programming and Scripting

awk array - first and last occurance

What I'm trying to do is, using awk, loading the log file into an array matching column 2, counting the match and finding the first occurance and last occurance of column 1 being it a date. 08052006:AAA 08052006:AAA 08052006:BBB 09052006:AAA 15052006:BBB 11052006:CCC 19052006:CCC... (5 Replies)
Discussion started by: ping
5 Replies

10. Shell Programming and Scripting

Removing the last occurance of string

I have a small query. I have a file containing the following lines abcd<12></12>fdfgdf<12>sdfgfg<12> sdfsdf<12></12>ytunfg<12> hggfhf<12>rtysb<12>zdfgdfg<12> Now I wish to delete ONLY the last occurance of string <12> from every lines of code. That mease my final output will be like this:... (7 Replies)
Discussion started by: dkhanna01
7 Replies
Login or Register to Ask a Question