I have go a different way with this script, but very curious about this.
First the script I am using
Code:
cat mac.sh
#!/bin/bash -x
ifconfig eth0| grep HWaddr |tr -s ' ' |cut -d' ' -f5
MAC=`ifconfig eth0| grep HWaddr |tr -s ' ' |cut -d' ' -f5`
grep "$MAC" maclist.txt|tr -s " " |cut -d" " -f1
HO1=`grep "$MAC" maclist.txt |tr -s " " |cut -d" " -f1`
printf ${HO1}
grep "$MAC" maclist.txt |tr -s " " |cut -d" " -f2
HO2=`grep "$MAC" maclist.txt |tr -s " " |cut -d" " -f2`
printf ${HO2}
A='00:23:AE:69:C0:F2'
printf ${A}
exit 0
And the output:
Code:
./mac.sh
+ ifconfig eth0
+ grep HWaddr
+ tr -s ' '
+ cut '-d ' -f5
00:23:AE:69:C0:F2
++ ifconfig eth0
++ grep HWaddr
++ tr -s ' '
++ cut '-d ' -f5
+ MAC=00:23:AE:69:C0:F2
+ grep 00:23:AE:69:C0:F2 maclist.txt
+ tr -s ' '
+ cut '-d ' -f1
om012274
++ grep 00:23:AE:69:C0:F2 maclist.txt
++ tr -s ' '
++ cut '-d ' -f1
+ HO1=om012274
+ printf om012274
om012274+ grep 00:23:AE:69:C0:F2 maclist.txt
+ tr -s ' '
+ cut '-d ' -f2
00:23:AE:69:C0:F2
++ grep 00:23:AE:69:C0:F2 maclist.txt
++ tr -s ' '
++ cut '-d ' -f2
+ HO2=$'00:23:AE:69:C0:F2\r'
+ printf $'00:23:AE:69:C0:F2\r'
+ A=00:23:AE:69:C0:F2
+ printf 00:23:AE:69:C0:F2
00:23:AE:69:C0:F2+ exit 0
The bit I am curious about is:
+ HO2=$'00:23:AE:69:C0:F2\r'
Anyone handy with text processing know about this?
Thanks