Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was trying to edit the output of a file using sed. The contents of file are

cat /tmp/Group_RM

I was trying to get the output as:

cat /tmp/Group_RM

I tried the below command but the output looked odd:

cat /tmp/Group_RM | sed 's/./_/g'

Output is:

____ ___

sed is replacing all characters with underscores. When I tried to replace "_" with ".", sed works perfectly.

share|improve this question
Please do not sign your posts, and note that you should indent code with four spaces, or select it and press Ctrl-K or click the {} code button. No need for HTML <br>s. Thanks! – slhck May 18 '13 at 12:30
up vote 7 down vote accepted

You need to escape the . like \.. . is a special metacharacter which matches any single character.

$ sed 's/\./_/g' Group_RM

On a side note, cat is not needed - sed can deal with files itself.

share|improve this answer
thanks a lot it worked perfectly :) – KumarJohn May 18 '13 at 11:25

The reason is that a dot is a special character in regular expressions. If you mean an actual dot, you need to escape it with \.

Also, you do not need cat, you can give the filename to sed directly. This works:

sed 's/\./_/g' myfile.txt
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .