GREP mac address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting GREP mac address
# 1  
Old 11-08-2014
GREP mac address

Hi,

mac.txt
My mac address is <Mac Address>.

How can i replace <Mac Address> with the actual of my computer?
I try to GREP command as below but i am unable to grep it to replace just <Mac Address>.
Code:
ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'

Million in Advance.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Cheers

Last edited by vbe; 11-08-2014 at 08:22 AM..
# 2  
Old 11-08-2014
There's many a solution to your problem. One of them:
Code:
sed "s/<Mac Address>/$(ifconfig eth0 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}')/" mac.txt
My mac address is 00:1f:c6:4c:d0:e2.

# 3  
Old 11-08-2014
Just awk?

Code:
awk 'NR==FNR {mac=$0;next} {sub(/<Mac Address>/, mac)}1' /sys/class/net/eth0/address mac.txt


Last edited by Aia; 11-08-2014 at 03:02 PM.. Reason: more idiomatic
# 4  
Old 11-28-2014
Hi,

thanks for all the suggestion but can i make it replace it in the actual file. What i want is the <Mac Address> will be replaced by the actual mac add in the file. Thanks.

Cheers
# 5  
Old 11-29-2014
Redirect the output of your command to a temporary file, and, when correct, mv (overwrite) that to the original file.
Some sed implementations have the -i (in place) option to overwrite immediately.
# 6  
Old 12-07-2014
Many thanks for all the help. I am close to achieve what i want.
I do not want the ":" which is uses another command line to remove

Code:
sed s/://g /usr/local/id.txt

but how can i merge it to the below command?

Code:
sed -i "s/<user>/$(ifconfig eth0 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}')/" /usr/local/id.txt

MTIA

Last edited by Don Cragun; 12-07-2014 at 07:08 AM.. Reason: Add CODE tags.
# 7  
Old 12-07-2014
How would you surmise this could be done?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

MAC Address - Four Interfaces with the same MAC Address

four interfaces with ifconfig all interfaces have the same mac. If is not set for unique. but it still works. what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies

2. Red Hat

No Mac address present,

I have installed RHEL 6 in my new system. My sytem is physically also connected with network, but after successfully installing it is not detecting the network. I checked, there is no /etc/sysconfig/network file present in my system. I manually created /etc/sysconfig/network file. The problem I... (5 Replies)
Discussion started by: Ankur Goyal
5 Replies

3. UNIX for Dummies Questions & Answers

Grep /Awk letters X - X in every line and print it as a mac address

hey i m kinda new to this so i will appreciate any help , i have this list of values: pwwn = 0x50012482009cd7a7 nwwn=0x50012482009cd7a6 port_id = 0x280200 pwwn = 0x5001248201bcd7a7 nwwn=0x5001248201bcd7a6 port_id = 0x280300 pwwn = 0x50012482009c51ad nwwn=0x50012482009c51ac port_id =... (4 Replies)
Discussion started by: boaz733
4 Replies

4. IP Networking

Tracing a MAC address to IP address: Solaris

Hi there I lost connectivity to one of our remote systems and when I checked the messages log I found the following: Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1 Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies

5. SCO

MAC address

hi every one please help i want to change mac address in sco unix 5.0.6 how can i do this (3 Replies)
Discussion started by: kaydream
3 Replies

6. Solaris

Get ip address from mac address

I have following message in my messages file on solaris 10 WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
Discussion started by: fugitive
6 Replies

7. IP Networking

How to Achive IP address through MAC(Ethernet) address

Hi sir, i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address....... but i'm nt getting that how i can pass the MAC address to Frame........ Please give me an idea for making such program... Thanks & regards Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies

8. IP Networking

How do I mask my MAC address

I posted this thread under BSD but realized that it actually belongs here instead.... makes more sense to put it under IP. So without further delay on to my problem ... I havent been using UNIX for that long, so this question might sound quite stupid to most of you. I want to know how to mask my... (2 Replies)
Discussion started by: PenguinDevil
2 Replies

9. UNIX for Dummies Questions & Answers

Mac address

Hi Can some one help me How do find out Mac address in Tru64 Unix Thank you (1 Reply)
Discussion started by: Syed_45
1 Replies

10. Programming

Get Mac Address

:( Hi I am trying to get Mac address of of my Sun server from my C program running on the host machine. Any suggestions . (1 Reply)
Discussion started by: ss_hpov
1 Replies
Login or Register to Ask a Question