The UNIX and Linux Forums  


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
Need Help with awk and arrays fusionX Shell Programming and Scripting 7 02-11-2008 06:41 PM
awk arrays imonthejazz Shell Programming and Scripting 1 09-21-2007 10:29 AM
ksh script - arrays sidamin810 Shell Programming and Scripting 13 07-18-2005 04:07 AM
KSH and arrays whited05 Shell Programming and Scripting 1 06-24-2005 01:07 PM
Two or more arrays in Awk nitin UNIX for Advanced & Expert Users 1 12-10-2001 09:37 PM

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 08-27-2007
craigsky craigsky is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 6
arrays in awk???

Been struggling with a problem, I have been trying to do this in awk, but am unable to figure this out, I think arrays have to be used, but unsure how to accomplish this.

I have a input file that looks like this:

141;ny;y;g
789;ct;e;e
23;ny;n;u
45;nj;e;u
216;ny;y;u
7;ny;e;e
1456;ny;e;g
2;ct;n;e

I want the output to look like this:

ny: 141 23 216 7 1456
ct: 789 2
nj: 45


Is this possible? I know it is, but I can't figure it out, would like to use awk if possible.

thanks in advance.
  #2 (permalink)  
Old 08-27-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
You can do something like that :

Code:
awk -F';' '
   {
      array[$2] = array[$2] " " $1;
   }
   END {
      for (i in array)
         print i ":" array[i];
   }
   ' inputfile

Jean-Pierre.
  #3 (permalink)  
Old 08-27-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
aigles,

Code:
array[$2] = ($2 in array[$2]) ? array[$2] " " $1 : $1;

  #4 (permalink)  
Old 08-27-2007
craigsky craigsky is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 6
thanks much, that did it!!!!
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 03:14 AM.


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