Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 would like to substitute characters in even columns with a different char, like this (with space):




h l o

How can I do this?

share|improve this question
up vote 1 down vote accepted
cat readme.txt | sed -e "s/\(.\)./\1 /g"

EDIT: I noticed the slashes is hidden unless I used code style. Fixed.

share|improve this answer

This will do it:

awk '{for(i=1;i<=length;i+=2) printf("%c ", substr($0, i, 1)); printf "\n"}' <filename>

awk processes each line in turn, the for loop processes every other character and prints it followed by a space

share|improve this answer
sed 's/(.)./\1 /g'

I may be missing backslashes for the parentheses.

share|improve this answer

Use extended regex option in sed:

sed -r 's;(.).;\1 ;g' input-file

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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