AnotherAlan
Technical User
Hi All,
I'm trying to write a ksh script that uses a nawk statement embedded between two for loops.
My issue is with getting nawk to recognise the second condition, in this case the $state.
It works fine for just the $robot and does what I expect it to.
i.e
nawk 'BEGIN {OFS=" "} $4=='"$robot"' {print $5,$1,$9}' /tmp/media | sort -n
OUTPUT:
1 UPX069 AVAILABLE
2 UPX128 AVAILABLE
3 UPX071 AVAILABLE
4 UPX113 AVAILABLE
5 UPX072 AVAILABLE
e.t.c
However, when I try and add to it with the second for loop and the $state my nawk output is blank.
CODE:
#!/bin/ksh
for robot in 0 1 ; do
((server=$robot+1))
for state in AVAILABLE FULL ACTIVE FROZEN; do
echo $state
printf "%-8s" "Slot:";printf "%-8s\n" "ID:"
nawk 'BEGIN {OFS=" "} $4=='"$robot"' && $9=='"$state"' {print $5,$1,$9}' /tmp/media | sort -n
done
done
I've tried doing it this way as well;
nawk 'BEGIN {OFS=" "} {if ($4=='"$robot"' && $9=='"$state"')}{print $5,$1,$9}' /tmp/media | sort -n
But this seems to ignore both the $4 and $9 matches.
I guess this is probably terrible code anyway, but it's xmas and I'm trying to pass the day by learning something useful. ;-)
Appreciate any help as always.
Alan
I'm trying to write a ksh script that uses a nawk statement embedded between two for loops.
My issue is with getting nawk to recognise the second condition, in this case the $state.
It works fine for just the $robot and does what I expect it to.
i.e
nawk 'BEGIN {OFS=" "} $4=='"$robot"' {print $5,$1,$9}' /tmp/media | sort -n
OUTPUT:
1 UPX069 AVAILABLE
2 UPX128 AVAILABLE
3 UPX071 AVAILABLE
4 UPX113 AVAILABLE
5 UPX072 AVAILABLE
e.t.c
However, when I try and add to it with the second for loop and the $state my nawk output is blank.
CODE:
#!/bin/ksh
for robot in 0 1 ; do
((server=$robot+1))
for state in AVAILABLE FULL ACTIVE FROZEN; do
echo $state
printf "%-8s" "Slot:";printf "%-8s\n" "ID:"
nawk 'BEGIN {OFS=" "} $4=='"$robot"' && $9=='"$state"' {print $5,$1,$9}' /tmp/media | sort -n
done
done
I've tried doing it this way as well;
nawk 'BEGIN {OFS=" "} {if ($4=='"$robot"' && $9=='"$state"')}{print $5,$1,$9}' /tmp/media | sort -n
But this seems to ignore both the $4 and $9 matches.
I guess this is probably terrible code anyway, but it's xmas and I'm trying to pass the day by learning something useful. ;-)
Appreciate any help as always.
Alan