5

I am new to the community and this is my first question, I hope I am doing it correctly.

My question: I am learning some networking and analysis and have a very long list of MAC addresses that I want to put in the same sentence using the command line but I do not know how.

Example: MAC addresses:

xx:xx:xx:xx:xx:xx:xx:xx
yy:yy:yy:yy:yy:yy:yy:yy
zz:zz:zz:zz:zz:zz:zz:zz

The output I need:

The mac address xx:xx:xx:xx:xx:xx:xx:xx is not found - but...
The mac address yy:yy:yy:yy:yy:yy:yy:yy is not found - but...
The mac address zz:zz:zz:zz:zz:zz:zz:zz is not found - but...

How can I achieve this?

I hope you have the time to help and excuse my ignorance, I am still learning and wouldn't ask if I didn't spend some time searching. I saw people using sed, awk, and perl but I understood nothing sense the whole linux world is new for me. Please provide me with some explanation with the commands so I learn how to do it myself for the next time.

3

Assuming your list is in a file called file with nothing else in it (as appears to be the case), you could use:

sed 's/.*/The mac address & is not found - but.../' file
  • s/old/new replace old with new
  • .* match any number of any characters on each line
  • & print what was matched earlier here

If you see the output you want, repeat the command (hit the up arrow to see and edit the previous command) adding redirection (>) to a new file at the end like this:

sed 's/.*/The mac address & is not found - but.../' file > newfile
3

Answer to first question:

sed 's/$/ is not found - but.../' FILENAME | sed 's/^/The mac address /'

This usage of sed just replaces fist string with the second one. $ means end of the line. ^ means beginning of the line.

Answer to second question:

sed 'N;s/\n/ /' FILENAME | sed 's/IP address:/This computer ip address is/' | sed 's/Computer name:/and is under the name/'

First sed merge every two lines. Remain seds replace old expression with new expression to build your new line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.