getline with a unique


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getline with a unique
# 1  
Old 03-02-2005
Computer getline with a unique

I have an inputfile that I trying to awk with a getline(Solaris v8 ksh). However I need to have the results be a unique. Is there a comparable command within awk to return a unique result? Or can you break out of the awk to add a uniq. I am looking for something more complex then a pipe command(which I can get to work but would like to embed everything in an awk then a script that has an awk command.). Any help would be great, and I appreciate any ideas anyone has.

amharm00:1004042:Harmet,Andrew M:10006058:10006024:
amharm00:1004042:Harmet,Andrew M:10006058:10006025:
amharm00:1004042:Harmet,Andrew M:10006058:10006026:
amharm00:1004042:Harmet,Andrew M:10006058:10006027:
axgiai00:1033315:Giaimo,Anthony:10003385:10003372:
axgiai00:1033315:Giaimo,Anthony:10003385:10003373:
axgiai00:1033315:Giaimo,Anthony:10003385:20000298:
bjkugl00:1002500:Kugler,Bill J:10006706:10006695:
bjkugl00:1002500:Kugler,Bill J:10006706:10006696:
wbcroo00:1002216:Crook,Wallace B:10007122:10007104:
wbcroo00:1002216:Crook,Wallace B:10007122:10007105:
# 2  
Old 03-02-2005
what is the desired output given this sample input?
why do you need 'getline'?
do you have ONE or TWO files to process/match?
# 3  
Old 03-02-2005
Computer

Sorry, I am taking the input and extracting $1, $2, $3, and $5. Using this information to create an output file that will add user data for generation into a mysql database.
I have been tasked to bring the limping version of the script into a production environment. It is a disaster, about 250 lines of code, 8 loops mixed with if conditions, and about 30 separate awk statements all piped with about 4 or 5 commands each. I have a light bulb idea of a better way to do it, but am still pretty new.
# 4  
Old 03-02-2005
I still don't understand the desired output, but......

nawk -F':' -v OFS=':' '{print $1, $2, $3, $5}' inputFile.txt
# 5  
Old 03-02-2005
Computer

If I awk it I will have $1 entered four times. What I am looking for is a way for within an awk script to have it return only one instance of $1. I was thinking a getline and then an if statement with a condition of $1 == $previous1 or something. But I am still working on the details.
# 6  
Old 03-02-2005
Quote:
Originally Posted by gozer13
If I awk it I will have $1 entered four times. What I am looking for is a way for within an awk script to have it return only one instance of $1. I was thinking a getline and then an if statement with a condition of $1 == $previous1 or something. But I am still working on the details.
so... for the case of $1="amharm00", what record would you like to return? There're FOUR of them.
# 7  
Old 03-03-2005
I am trying to return only one of the responses of the four. It doesn't really matter, I think I may have figured it out though. I read something last night, and the lightbulb glowed that getline isn't used for what I thought it was. Thanks for the help vgersh I appriciate it.

..gozer13
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk with if, getline, and another if

Howdy Folks, It seems like it is always awk that confuses the heck out of me and I even have books and examples. I have this line: awk '{if (/clientIP/)(SRV = $NF); if ($2 ~ /BUNDLE-GIM/) getline; if ($2 ~ /r100595/) {print SRV,"BUNDLE-GIM",$2}}' post.txt to parse this text: <api... (4 Replies)
Discussion started by: port43
4 Replies

2. Shell Programming and Scripting

awk getline

Hi, I have an awk script with the following function in it . function cmd( c ) { while( ( c | getline foo) > 0 ){ return foo ; close( c ); } } c =... (4 Replies)
Discussion started by: MetaMan
4 Replies

3. UNIX for Dummies Questions & Answers

Print unique lines without sort or unique

I would like to print unique lines without sort or unique. Unfortunately the server I am working on does not have sort or unique. I have not been able to contact the administrator of the server to ask him to add it for several weeks. (7 Replies)
Discussion started by: cokedude
7 Replies

4. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

5. Programming

getline() and fclose()

Hi All, When I do man getline on my Linux system (in BASH), I see an example C code where a file is being read using getline() function. Now, my question is why there is no fclose() to close the open file pointer? People who don't have a Linux system, this is the code that I am referring... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Programming

getline()

I can not get 'getline()' to compile. I have tried. string curLine; //= compiler error char* curLine; //=compiler error char curLine; //=compiler error Every example I see uses a string as a getline(); parameter. It does not work for me on Fedora14 with gcc-c++. Thank you so much. This... (1 Reply)
Discussion started by: sepoto
1 Replies

7. Shell Programming and Scripting

errors while using getline

i wrote following script to test getline BEGIN{ while ( "who" | getline > 0) nr++ print nr } when i run this script as awk -f scriptname (2 Replies)
Discussion started by: asalman.qazi
2 Replies

8. Shell Programming and Scripting

get part of file with unique & non-unique string

I have an archive file that holds a batch of statements. I would like to be able to extract a certain statement based on the unique customer # (ie. 123456). The end for each statement is noted by "ENDSTM". I can find the line number for the beginning of the statement section with sed. ... (5 Replies)
Discussion started by: andrewsc
5 Replies

9. Programming

'getline' questions

I have a C program I've written that includes a 'getline' call that is used to read a line at a time from a file and process the information in each line. A potential problem comes up since I don't know the maximum length of each line; right now I'm using a constant of 256, but that might not be... (2 Replies)
Discussion started by: cleopard
2 Replies

10. UNIX for Dummies Questions & Answers

utility of getline here?

hi , I got a script that I don't understand. awk '{ command="echo "$1 command | getline echome close(command) print $0 "\t" echome }' < user.list It reads the file user.list user.list London John Bridge Peter and sends the stream to the awk command. I don't understand what is... (3 Replies)
Discussion started by: remid1985
3 Replies
Login or Register to Ask a Question