Ok after searching, I figured out I can't use a variable in a pattern
search in awk. But it hard for me to give it up since it works so
cleanly. The awk statement below gives me the exact output I need.
Except for the fact it won't let me change the the pattern for $2.
Basically, I need to start/stop all devices on the same NET $2
identified by $6. I used uniq because the restart/stop command only
needs device number and it will restart all the ****ts in that NET.
I looked at the other replies and couldn't figure out how to make
'grep' work in this situation.
Can anyone suggest another solution path? I'm not looking specifically
for an awk solution.
awk '($2 ~/-NET=3/) && ($5 ~ /-SYC/) { print $6 ; }' CONFIG.CFG >
sort.tmp
input=`uniq
sort.tmp`
echo $input
results:
459 106 107 108 109 110
Example of CONFIG.CFG's format
socket12101 -NET=1 -CRYPT=0 -TIMEOUT=0 -MCW 103
socket12102 -NET=1 -CRYPT=0 -TIMEOUT=0 -SYC 103
socket12103 -NET=1 -CRYPT=0 -TIMEOUT=0 -SYC 111
socket12114 -NET=3 -CRYPT=0 -TIMEOUT=0 -MCW 459
socket12104 -NET=3 -CRYPT=0 -TIMEOUT=0 -SYC 459
socket12105 -NET=3 -CRYPT=0 -TIMEOUT=0 -SYC 106
socket12106 -NET=3 -CRYPT=0 -TIMEOUT=0 -SYC 107
socket12107 -NET=3 -CRYPT=0 -TIMEOUT=0 -SYC 107
.....