Inserting a space between each letter

Last update on January 12, 2009 08:55 AM by jak58
Published by jak58

Inserting a space between each letter








Insert a space between each letter.

$ echo -e "hello life\nand hello to you" | sed 's/./& /g'
h el l o  l i f e
a n d  h e l l o  t o  y o u
  • The problem is that the natural space between each word is doubled. To solve this just add:



$ echo -e "hello life\nand hello to you" | sed 's/./& /g;s/  / /g'
h el l o l i f e
a n d h e l l o t o y o u
$  
  • Here is a variant. Compared with the previous replacement and done in a single shot s///

$ echo -e "hello life\nand hello to you" | sed -r 's/([^ ])/\1 /g'
h el l o  l i f e
a n d  h e l l o  t o  y o u
  • If you do not want to use the-r option

sed 's/\([^ ]\)/\1 /g'


[^...] class character
  • [^...] - Is a character class complemented which means "to recognize a non-listed character" , do not sonfuse with "not to recognize a listed character.
  • In our case can be translated "to recognize a character that is not space."
Best answers for « Inserting a space between each letter » in :
Inserting space between each letter Show Inserting space between each letter $ echo -e "How are you\n everything alright" | sed 's/./& /g' H o w a r e y o u E v e r y t h i n g a l r I g h t The disadvantage is that the natural space between each word...
Sed - inserting spaces Show Sed - inserting spaces Insert a blank line after each sentence (punctuated by a carriage return) sed G file.txt Insert a blank line after each sentence (punctuated by a carriage return), without taking into account the existing white...
Capitalize the 1st letter of each word Show Capitalize the 1st letter of each word Below are two ways to proceed: Method 1 sed-r 's /(^.|.) / \ U & / g' Method 2 sed 's / ^. \ | [a-z] / \ U & / g' Method 3 sed-r 's / \
[Outlook Express] Create letter paper / Insert background image Show[Outlook Express] Create letter paper / Insert background image The letter paper is an Outlook Express feature allowing sending emails with illustrations (images, text, etc.) as background. Creating letterhead under Outlook Express In the...
Set the first letter of a word in capital ShowSet the first letter of a word/phrase in capital Gsed 4.0 and higher sed 's/^./\u&/' Example : $ echo "how are you" | sed 's/^./\u&/' How are you $ echo -e "how are you/ everything alright" | sed 's/^./\u&/' How are...
How to make a space in your html document ShowHow to make a space in your html document In HTML there is no way that the web browser can recognise the spaces inserted consecutively in between the letters. You can either try it in EI, Mozilla and Opera. The only way to do so is...
Download SequoiaView ShowSequoiaView is a program which allows to visualize the hard disk space. Each arborescence and the files which it contains are represented by a gleaming metal cushion. Each file, each arborescence has its sense of orientation. With this software, the...
Download Fretless Space Explorer ShowWould you like to know the size of each folder on your hard disk? Would you like to clean your hard disk but you do not where to start? Fretless Space Explorer is a very useful software to manage and maintain your hard disks. Contrary to Windows...
PC assembly - Inserting memory modules ShowInserting RAM modules There are various types of random access memory. The latest motherboards are equipped with DDR2 or DDR memory. Some are even equipped with RAMBus memory. The oldest ones actually have SDRAM connectors, or even EDO RAM...
PC assembly - Inserting expansion cards ShowInserting expansion cards Expansion cards are plugged into expansion slots. There are several types of slots: ISA slots run at 16 bits. Few computers still use this type of slot as the bus runs at a relatively slow speed. PCI slots run at 32...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...