LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-12-2009, 08:56 PM   #1
espiesior
LQ Newbie
 
Registered: Apr 2007
Posts: 5

Rep: Reputation: 0
How to insert a space between all characters


Hello all, I would really appreciate any help with this!

I have a file with a large(!) list of words:

Code:
apple
banana
happy
easter
etc.
Using bash, I would like to insert a space between every character. (However, no spaces at the beginning or end of the word.)

For example:
Code:
a p p l e
b a n a n a
h a p p y
e a s t e r
e t c .

How can I go about this in bash?

Thank you for any help!

Last edited by espiesior; 04-12-2009 at 08:57 PM.
 
Old 04-12-2009, 09:21 PM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Does it have to be bash? The command sed 's/\(.\)/\1 /g;s/ $//' words works quite well.
Code:
$ cat words
apple
banana
happy
easter
etc.
$ sed 's/\(.\)/\1 /g;s/ $//' words
a p p l e
b a n a n a
h a p p y
e a s t e r
e t c .
Note: Since the dot matches any character, the above will just add a space after every character in the file with no attempt to verify that the character string is actually a word.
 
Old 04-12-2009, 09:28 PM   #3
espiesior
LQ Newbie
 
Registered: Apr 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Thank you, will try it out!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert characters by ascii code? J_Szucs Linux - General 14 06-17-2017 12:33 PM
Any tool to insert a newline each X characters in a file? neoAKiRAz Programming 5 05-09-2007 07:15 PM
using perl to insert special characters into mysql database ihopeto Programming 5 12-25-2006 04:08 PM
using sed to insert lines with special characters disorderly Linux - Software 26 04-20-2006 05:30 PM
how to insert special characters set2004 Linux - Newbie 2 08-05-2004 10:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration