I am trying to use AWK to search a text file and pull out a field. I want to take the output of the awk, strip off the first eleven characters and place that into a variable in a bash script.
The test script I am using for proof of concept is this:
Code:
#!/bin/bash
# test searching a file for an ip address based on an input variable
MSR=unset
echo "enter your PE router :"
read MSR
gawk -v pe="$MSR" '$1 == pe { print $NF }' lo1map
echo ""
echo ""
RD=$(gawk -v pe="$MSR" '$1 == pe { FS= "."} ; { print $5 }' lo1map)
sleep 3
echo "$MSR has a route descriptor of $RD"
this gives me an output of:
-bash-3.2$ ./greptest1
enter your PE router :
router1.nyr
192.168.0.50
router1.nyr has a route descriptor of
~~~~~~~~ several blank lines later~~~~~~~
66
53
78
62
70
69
79
58
68
What I am expecting for output is:
-bash-3.2$ ./greptest1
enter your PE router :
router1.nyr
192.168.0.50
router1.nyr has a route descriptor of 50
My input file lo1map looks like this (It's a lot longer though)
router1.ald 192.168.0.9
router1.bol 192.168.0.17
router1.chd 192.168.0.11
router1.dan 192.168.0.13
router1.dck 192.168.0.3
router1.den 192.168.0.15
router1.ft3 192.168.0.25
router1.lay 192.168.0.5
router1.mmd 192.168.0.19
router1.nyr 192.168.0.50
Thanks in advance!