The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get sysname with getline in awk timj123 Shell Programming and Scripting 2 02-24-2008 10:43 PM
NAWK getline function Raynon Shell Programming and Scripting 5 11-28-2007 03:30 AM
awk getline help maybe? chlawren Shell Programming and Scripting 0 10-24-2007 10:56 AM
utility of getline here? remid1985 UNIX for Dummies Questions & Answers 3 11-12-2006 01:38 PM
awk:Problem with getline Klashxx Shell Programming and Scripting 3 05-12-2006 06:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-02-2005
gozer13's Avatar
gozer13 gozer13 is offline
Registered User
  
 

Join Date: Dec 2004
Location: Salt Lake City, Utah
Posts: 46
Talking 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 (permalink)  
Old 03-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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 (permalink)  
Old 03-02-2005
gozer13's Avatar
gozer13 gozer13 is offline
Registered User
  
 

Join Date: Dec 2004
Location: Salt Lake City, Utah
Posts: 46
Talking

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 (permalink)  
Old 03-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
I still don't understand the desired output, but......

nawk -F':' -v OFS=':' '{print $1, $2, $3, $5}' inputFile.txt
  #5 (permalink)  
Old 03-02-2005
gozer13's Avatar
gozer13 gozer13 is offline
Registered User
  
 

Join Date: Dec 2004
Location: Salt Lake City, Utah
Posts: 46
Talking

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 (permalink)  
Old 03-02-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0