Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between every letter

How can I add spaces between every character or symbol within a UTF-8 document? E.g. 123hello! becomes 1 2 3 h e l l o !.

  • I have BASH, OpenOffice.org, and gedit, if any of those can do that.
  • I don't care if it sometimes leaves extra spaces in places (e.g. 2 or 3 spaces in a single place is no problem).
like image 251
Village Avatar asked Jan 02 '12 01:01

Village


People also ask

What is it called when you add space between letters?

Kerning refers to the amount of space between two letters (or other characters: Numbers, punctuation, etc.) and the process of adjusting that space to avoid awkward-looking gaps between your letters and improve legibility. In this article, we will outline how to kern like a professional designer.

How do you add spaces in C?

In C language, we can directly add spaces. printf(“ ”); This gives a space on the output screen.


2 Answers

Shortest sed version

sed 's/./& /g'

Output

$ echo '123hello!' |  sed 's/./& /g'
1 2 3 h e l l o !

Obligatory awk version

awk '$1=$1' FS= OFS=" "

Output

$ echo '123hello!' |  awk '$1=$1' FS= OFS=" "
1 2 3 h e l l o !
like image 92
SiegeX Avatar answered Nov 09 '22 23:11

SiegeX


sed(1) can do this:

$ sed -e 's/\(.\)/\1 /g' < /etc/passwd
r o o t : x : 0 : 0 : r o o t : / r o o t : / b i n / b a s h 
d a e m o n : x : 1 : 1 : d a e m o n : / u s r / s b i n : / b i n / s h 

It works well on e.g. UTF-8 encoded Japanese content:

$ file japanese 
japanese: UTF-8 Unicode text
$ sed -e 's/\(.\)/\1 /g' < japanese 
E X I F 中 の 画 像 回 転 情 報 対 応 に よ り 、 一 部 画 像 ( 特 に 『 
$ 
like image 38
sarnold Avatar answered Nov 09 '22 22:11

sarnold