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?

link|improve this question

80% accept rate
feedback

4 Answers

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.

link|improve this answer
feedback

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

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

I may be missing backslashes for the parentheses.

link|improve this answer
feedback

Use extended regex option in sed:

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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