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
Array inside an array manas_ranjan UNIX for Advanced & Expert Users 5 06-10-2008 02:25 PM
array ccp Shell Programming and Scripting 3 02-26-2008 03:19 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 08:42 AM
array in awk asal_email2 Shell Programming and Scripting 5 06-13-2005 07:25 AM
Do I need an array here? TheCrunge Shell Programming and Scripting 5 04-19-2005 03:20 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 11-28-2007
djsal djsal is offline
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
  #2 (permalink)  
Old 11-28-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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]
}
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 07:04 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