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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array inside an array manas_ranjan UNIX for Advanced & Expert Users 5 06-10-2008 11:25 AM
array ccp Shell Programming and Scripting 3 02-26-2008 12:19 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
array in awk asal_email2 Shell Programming and Scripting 5 06-13-2005 04:25 AM
Do I need an array here? TheCrunge Shell Programming and Scripting 5 04-19-2005 12:20 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-28-2007
Registered User
 

Join Date: Apr 2004
Location: Long Island Ny
Posts: 23
I need help with an array!

I have the following file:

Johnny|"New York, NY"|Driver,LNU
Bob|"Los Angeles, CA"|Crew,ASA
JIM|"Rochester, NY"|Cook,GHG
Phil|"New York, NY"|Teacher,"LNU,ASA,CCC,JJJ"



What I need to output is the following:

Johnny|"New York, NY"|Driver,LNU
Bob|"Los Angeles, CA"|Crew,ASA
JIM|"Rochester, NY"|Cook,GHG
Phil|"New York, NY"|Teacher,LNU
Phil|"New York, NY"|Teacher,ASA
Phil|"New York, NY"|Teacher,CCC
Phil|"New York, NY"|Teacher,JJJ

Basically, I want to create a new row for every entry in the 4th field.

Thanks in advance for any help!!!!

Sal
Reply With Quote
Forum Sponsor
  #2  
Old 11-28-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
something along these lines...

nawk -f dj.awk myFile

dj.awk:
Code:
BEGIN {
  FS=OFS="|"
  SEP_com=","

  FLD_prof="3"
  qq=sprintf("%c", 034)
}
!index($FLD_prof, qq){ print; next }

{
   prof=substr($FLD_prof, 1, index($FLD_prof, SEP_com)-1)
   list=substr($FLD_prof, index($FLD_prof, SEP_com)+1)
   gsub(qq, "", list)
   n=split(list, listA, SEP_com)
   for(i=1; i<=n; i++)
      print $1, $2, prof SEP_com listA[i]
}
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0