The first version of the awk script uses a while !~ so that I read my file until the next block, block id = 'RESPN'.
This code just hangs in the middle of writing the file.
The second version specifies the records that are in each block and uses an equals to rather than a not equals- this works fine- any ideas why the not equals hangs half way through the file?
Command line
awk -f get_RRJ_REJ.sh FLAG='"REJCT"' /appl/out/archive/rnj/GTM01.PN00000.RNJ >> RJT_RRJ.txt
Version 1
BEGIN { FS="," }
{
z = 1
while ($1 ~ /RESPN/) {
rec[1] = $0
x = 1
getline
while ($1 !~ /RESPN/) {
++x
rec[x] = $0
if ($3 == FLAG) {
z = 2
}
getline
}
if (z == 2) {
for ( k = 1; k <= x; ++k) {
print rec[k]
}
if ($1 ~ /TRAIL/){
exit
}
}
}
}
Version 2
BEGIN { FS="," }
{
z = 1
while ($1 ~ /RESPN/) {
rec[1] = $0
x = 1
getline
while ($1 ~ /TRANS/ || $1 ~ /TROUT/ || $1 ~ /MTPNT/ || $1 ~ /REJRS/ || $1 ~ /ASSET/) {
++x
rec[x] = $0
if ($3 == FLAG) {
z = 2
}
getline
}
if (z == 2) {
for ( k = 1; k <= x; ++k) {
print rec[k]
}
if ($1 ~ /TRAIL/){
exit
}
}
}
}
This code just hangs in the middle of writing the file.
The second version specifies the records that are in each block and uses an equals to rather than a not equals- this works fine- any ideas why the not equals hangs half way through the file?
Command line
awk -f get_RRJ_REJ.sh FLAG='"REJCT"' /appl/out/archive/rnj/GTM01.PN00000.RNJ >> RJT_RRJ.txt
Version 1
BEGIN { FS="," }
{
z = 1
while ($1 ~ /RESPN/) {
rec[1] = $0
x = 1
getline
while ($1 !~ /RESPN/) {
++x
rec[x] = $0
if ($3 == FLAG) {
z = 2
}
getline
}
if (z == 2) {
for ( k = 1; k <= x; ++k) {
print rec[k]
}
if ($1 ~ /TRAIL/){
exit
}
}
}
}
Version 2
BEGIN { FS="," }
{
z = 1
while ($1 ~ /RESPN/) {
rec[1] = $0
x = 1
getline
while ($1 ~ /TRANS/ || $1 ~ /TROUT/ || $1 ~ /MTPNT/ || $1 ~ /REJRS/ || $1 ~ /ASSET/) {
++x
rec[x] = $0
if ($3 == FLAG) {
z = 2
}
getline
}
if (z == 2) {
for ( k = 1; k <= x; ++k) {
print rec[k]
}
if ($1 ~ /TRAIL/){
exit
}
}
}
}