SED command - MAC address
up vote
0
down vote
favorite
I use the MAC address of the machine as userid and would like to update a file (display.txt) that will display the userid/expiry. How do I replace the expdate in display.txt with the date in expdate.txt corresponding to the MAC address.
I succeed with the userid part, with:
sed -i "s/user/$(ifconfig eth0 |
grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}')/"
/user/id/display.txt > /dev/null
display.txt:
UserID: user
User expiring on expdate
expdate.txt:
user = 00:09:34:2C:66:AB
expdate = 2017-05-20
user = 00:09:34:29:86:6C
expdate = 2017-08-23
I would like to have:
display.txt:
UserID: 00:09:34:29:86:6C
User expiring on 2017-08-23
sed
add a comment |
up vote
0
down vote
favorite
I use the MAC address of the machine as userid and would like to update a file (display.txt) that will display the userid/expiry. How do I replace the expdate in display.txt with the date in expdate.txt corresponding to the MAC address.
I succeed with the userid part, with:
sed -i "s/user/$(ifconfig eth0 |
grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}')/"
/user/id/display.txt > /dev/null
display.txt:
UserID: user
User expiring on expdate
expdate.txt:
user = 00:09:34:2C:66:AB
expdate = 2017-05-20
user = 00:09:34:29:86:6C
expdate = 2017-08-23
I would like to have:
display.txt:
UserID: 00:09:34:29:86:6C
User expiring on 2017-08-23
sed
2
do you want to loop it through users and expiry dates. Or only one is enough?
– Pappu
Jan 1 '17 at 5:52
Which operating system do you use?
– Cyrus
Jan 1 '17 at 10:32
all machines will download the same file and upon booting it will pull uses the mac address as the user and then find its expiring date from this file (expdate.txt).
– Dick
Jan 1 '17 at 11:51
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I use the MAC address of the machine as userid and would like to update a file (display.txt) that will display the userid/expiry. How do I replace the expdate in display.txt with the date in expdate.txt corresponding to the MAC address.
I succeed with the userid part, with:
sed -i "s/user/$(ifconfig eth0 |
grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}')/"
/user/id/display.txt > /dev/null
display.txt:
UserID: user
User expiring on expdate
expdate.txt:
user = 00:09:34:2C:66:AB
expdate = 2017-05-20
user = 00:09:34:29:86:6C
expdate = 2017-08-23
I would like to have:
display.txt:
UserID: 00:09:34:29:86:6C
User expiring on 2017-08-23
sed
I use the MAC address of the machine as userid and would like to update a file (display.txt) that will display the userid/expiry. How do I replace the expdate in display.txt with the date in expdate.txt corresponding to the MAC address.
I succeed with the userid part, with:
sed -i "s/user/$(ifconfig eth0 |
grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}')/"
/user/id/display.txt > /dev/null
display.txt:
UserID: user
User expiring on expdate
expdate.txt:
user = 00:09:34:2C:66:AB
expdate = 2017-05-20
user = 00:09:34:29:86:6C
expdate = 2017-08-23
I would like to have:
display.txt:
UserID: 00:09:34:29:86:6C
User expiring on 2017-08-23
sed
sed
edited Nov 25 at 23:45
Rui F Ribeiro
38.3k1477127
38.3k1477127
asked Jan 1 '17 at 4:34
Dick
6
6
2
do you want to loop it through users and expiry dates. Or only one is enough?
– Pappu
Jan 1 '17 at 5:52
Which operating system do you use?
– Cyrus
Jan 1 '17 at 10:32
all machines will download the same file and upon booting it will pull uses the mac address as the user and then find its expiring date from this file (expdate.txt).
– Dick
Jan 1 '17 at 11:51
add a comment |
2
do you want to loop it through users and expiry dates. Or only one is enough?
– Pappu
Jan 1 '17 at 5:52
Which operating system do you use?
– Cyrus
Jan 1 '17 at 10:32
all machines will download the same file and upon booting it will pull uses the mac address as the user and then find its expiring date from this file (expdate.txt).
– Dick
Jan 1 '17 at 11:51
2
2
do you want to loop it through users and expiry dates. Or only one is enough?
– Pappu
Jan 1 '17 at 5:52
do you want to loop it through users and expiry dates. Or only one is enough?
– Pappu
Jan 1 '17 at 5:52
Which operating system do you use?
– Cyrus
Jan 1 '17 at 10:32
Which operating system do you use?
– Cyrus
Jan 1 '17 at 10:32
all machines will download the same file and upon booting it will pull uses the mac address as the user and then find its expiring date from this file (expdate.txt).
– Dick
Jan 1 '17 at 11:51
all machines will download the same file and upon booting it will pull uses the mac address as the user and then find its expiring date from this file (expdate.txt).
– Dick
Jan 1 '17 at 11:51
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I found a one-liner solution using grep and sed:
mac=$(ifconfig eth1 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'); grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display.txt
and to validate it works with any mac address I tested with:
mac=$(echo "00:09:34:29:86:6C") ; grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display2.txt
I generated the output from scratch, if you need a replacement in an existing file, I suggest to use a templating language like mustache. The Bash version is on GitHub
However because it seems you need to re-use the mac address (for searching first and then for the output) I suggest to make a bash script
and it would be more re-usable.
add a comment |
up vote
0
down vote
By concatenating sed
outputs:
sed -e 's/user/UserID/g' expdate.txt | sed -e 's/ //g' | sed -e 's/=/: /g' | sed -e 's/expdate:/User expiring on/g' > display.txt
(It's pretty sure that this could be done also with only one sed
)
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I found a one-liner solution using grep and sed:
mac=$(ifconfig eth1 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'); grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display.txt
and to validate it works with any mac address I tested with:
mac=$(echo "00:09:34:29:86:6C") ; grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display2.txt
I generated the output from scratch, if you need a replacement in an existing file, I suggest to use a templating language like mustache. The Bash version is on GitHub
However because it seems you need to re-use the mac address (for searching first and then for the output) I suggest to make a bash script
and it would be more re-usable.
add a comment |
up vote
0
down vote
I found a one-liner solution using grep and sed:
mac=$(ifconfig eth1 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'); grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display.txt
and to validate it works with any mac address I tested with:
mac=$(echo "00:09:34:29:86:6C") ; grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display2.txt
I generated the output from scratch, if you need a replacement in an existing file, I suggest to use a templating language like mustache. The Bash version is on GitHub
However because it seems you need to re-use the mac address (for searching first and then for the output) I suggest to make a bash script
and it would be more re-usable.
add a comment |
up vote
0
down vote
up vote
0
down vote
I found a one-liner solution using grep and sed:
mac=$(ifconfig eth1 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'); grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display.txt
and to validate it works with any mac address I tested with:
mac=$(echo "00:09:34:29:86:6C") ; grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display2.txt
I generated the output from scratch, if you need a replacement in an existing file, I suggest to use a templating language like mustache. The Bash version is on GitHub
However because it seems you need to re-use the mac address (for searching first and then for the output) I suggest to make a bash script
and it would be more re-usable.
I found a one-liner solution using grep and sed:
mac=$(ifconfig eth1 | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'); grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display.txt
and to validate it works with any mac address I tested with:
mac=$(echo "00:09:34:29:86:6C") ; grep "$mac" expdate.txt -A 1 | sed -r ':a;N;$!ba;s!user.*=.(..:..:..:..:..:..).*expdate.*=.(....-..-..)!UserID: 1nUser expiring on 2!g' > display2.txt
I generated the output from scratch, if you need a replacement in an existing file, I suggest to use a templating language like mustache. The Bash version is on GitHub
However because it seems you need to re-use the mac address (for searching first and then for the output) I suggest to make a bash script
and it would be more re-usable.
answered Jan 19 '17 at 11:46
рüффп
75831529
75831529
add a comment |
add a comment |
up vote
0
down vote
By concatenating sed
outputs:
sed -e 's/user/UserID/g' expdate.txt | sed -e 's/ //g' | sed -e 's/=/: /g' | sed -e 's/expdate:/User expiring on/g' > display.txt
(It's pretty sure that this could be done also with only one sed
)
add a comment |
up vote
0
down vote
By concatenating sed
outputs:
sed -e 's/user/UserID/g' expdate.txt | sed -e 's/ //g' | sed -e 's/=/: /g' | sed -e 's/expdate:/User expiring on/g' > display.txt
(It's pretty sure that this could be done also with only one sed
)
add a comment |
up vote
0
down vote
up vote
0
down vote
By concatenating sed
outputs:
sed -e 's/user/UserID/g' expdate.txt | sed -e 's/ //g' | sed -e 's/=/: /g' | sed -e 's/expdate:/User expiring on/g' > display.txt
(It's pretty sure that this could be done also with only one sed
)
By concatenating sed
outputs:
sed -e 's/user/UserID/g' expdate.txt | sed -e 's/ //g' | sed -e 's/=/: /g' | sed -e 's/expdate:/User expiring on/g' > display.txt
(It's pretty sure that this could be done also with only one sed
)
answered Jan 19 '17 at 11:58
Zumo de Vidrio
1,283319
1,283319
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f334067%2fsed-command-mac-address%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
do you want to loop it through users and expiry dates. Or only one is enough?
– Pappu
Jan 1 '17 at 5:52
Which operating system do you use?
– Cyrus
Jan 1 '17 at 10:32
all machines will download the same file and upon booting it will pull uses the mac address as the user and then find its expiring date from this file (expdate.txt).
– Dick
Jan 1 '17 at 11:51