Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to substitute characters in even columns with a different char, like this (with space):

In:

hello

Out:

h l o

How can I do this?

share|improve this question
add comment

4 Answers 4

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
add comment

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
add comment
sed 's/(.)./\1 /g'

I may be missing backslashes for the parentheses.

share|improve this answer
add comment

Use extended regex option in sed:

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

share|improve this answer
add comment

Your Answer

 
discard

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.