tags:

views:

320

answers:

5

I'm having a hard time trying to remove the colons in a list of MAC addresses.

My file:

00:21:5A:28:62:BF
00:24:81:0A:04:44

Expected Output:

00215A2862BF
0024810A0444

Any ideas on how could I do this? Thanks a lot in advance.

+1  A: 
echo "00:21:5A:28:62:BF" | sed -e 's/://g'
00215A2862BF
lothar
Thank you very much! That's exactly what I wanted!
nmuntz
+10  A: 

Given your tags, you want to accomplish this in a shell:

cat file | sed s/://g

edit: you don't really need the cat either if you are reading from a file:

sed s/://g file
andri
That was extremely fast ! Thank you very much!
nmuntz
Isn't that a useless use of cat? sed s/://g file would work just as well without having to invoke another process. See http://partmaps.org/era/unix/award.html
Sinan Ünür
If you want to edit the file in place, just add the `-i` option to the sed command: `sed -i s/://g file` which will alter the file in place rather than printing the result.
Drew Stephens
+7  A: 
perl -pe "s/://g" yourfile
Sinan Ünür
Using both -n and -p is pointless. They do the same thing, except -p prints after executing the code, while -n does not.
zigdon
Agreed, I forgot to delete the 'n'.
Sinan Ünür
+1  A: 

tr -d ':' < file

will probably work too, though I don't have a command line handy to check the syntax.

Anon Guy
A: 

How would i do the reverse if i'm running Mac OS X. Leopard?

@Charles Hines answers are not the place to ask new questions. At the top of the page is an "Ask Question" button. Press that and ask your question. You can refer back to this question in yours if you wish.
Chas. Owens
sed -e 's/\(..\)/\1:/g' -e 's/:$//'
Telemachus