JSKOBS
1
Hi, Below command is working as expected, but would like to know how to club the two AWK scripts in the command into one
echo -e "MMS000101S0203430A|20180412E|\nMMB0001INVESTMENT||107-86193-01-03|\nMMB0001FUND||107-86193-04-01|\nMMC9991 " | awk -F'|' -v OFS=, '/^MMC9991/{print r"|"s,t; next} /^MMS0001/ { r=substr($1,8); s=substr($2,1,8);next} /^MMB0001/ { gsub("-",""); t=(t?t OFS:"")$3 }' | awk -F "," '{for (i=2;i<=NF;i++)print $1,$i}' OFS="|"
RudiC
2
Would this come near of what you need:
echo -e "MMS000101S0203430A|20180412E|\nMMB0001INVESTMENT||107-86193-01-03|\nMMB0001FUND||107-86193-04-01|\nMMC9991 " |
awk -F'|' -v OFS=, '
/^MMC9991/ {gsub ("-", "", t)
n = split (t, T, OFS)
for (i=1; i<n; i++) print rs, T
}
/^MMS0001/ {rs = substr($1,8) FS substr($2,1,8)
}
/^MMB0001/ {t = t $3 OFS
}
'
01S0203430A|20180412,107861930103
01S0203430A|20180412,107861930401
2 Likes
JSKOBS
3
Apologies, i missed
in my command, updated command below:
echo -e "MMS000101S0203430A|20180412E|\nMMB0001INVESTMENT||107-86193-01-03|\nMMB0001FUND||107-86193-04-01|\nMMC9991 " | awk -F'|' -v OFS=, '/^MMC9991/{print r"|"s,t; r=s=t=""; next} /^MMS0001/ { r=substr($1,8); s=substr($2,1,8);next} /^MMB0001/ { gsub("-",""); t=(t?t OFS:"")$3 }' | awk -F "," '{for (i=2;i<=NF;i++)print $1,$i}' OFS="|"
RudiC
4
So? Why don't you insert it into the proposal?
1 Like