![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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]
}
|
||||
| Google The UNIX and Linux Forums |