Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing based on following field

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
Hey all something got me stumped...

I have a list of about 200 mac addresses in 0004F2061276 format. I need to enter the colon between:

00:04:F2:06:12:76 tried looking for everything but came up empty

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
A starting point:
echo '0004F2061276' | awk '{for(i=10;i>=2;i-=2)$0=substr($0,1,i)":"substr($0,i+1);print}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV you rock. I was stuck on stupid going with this route:

while IFS="" read -r -- LINE; do LINE="${LINE/#([1-9])([0-9][0-9][!0-9])/\1:\2}"; LINE="${LINE/#([1-9][0-9])([0-9][0-9][!0-9])/\1:\2}"; print "${LINE}"; done < filename

perl -e 'print $i=pack(c5,(40*2),sqrt(7600),(unpack(c,Q)-3+1+3+3-7),oct(104),10,oct(101));'
 
A sed alternative:

[tt]echo '0004F2061276' | sed 's/\(..\)/\1:/g;s/:$//'[/tt]

Annihilannic.
 
here's another solution using fold and tr:

$ MAC=0004F2061276
$ CMAC=$(echo "${MAC}\c"|fold -w2|tr '\n' ':')
$ echo $CMAC
00:04:F2:06:12:76


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top