nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Shell script to insert a blank character after each character

This is a discussion on Shell script to insert a blank character after each character within the Shell scripting forums, part of the Development/Scripting category; My input file with some scientific data numbers is as follows: Code: 1921681234 2254859678 6484684648 I need those numbers in ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2009, 10:57 AM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default Shell script to insert a blank character after each character

My input file with some scientific data numbers is as follows:
Code:
1921681234
2254859678
6484684648
I need those numbers in the following format to feed to another program called foo:
Code:
1 9 2 1 6 8 1 2 3 4 
2 2 5 4 8 5 9 6 7 8
So how do I insert a blank character after each character?
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
  #2 (permalink)  
Old 08-07-2009, 11:02 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,710
Thanks: 11
Thanked 245 Times in 184 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Try:
Code:
sed 's/./& /g' input.txt | foo
sed will go through each line and add a blank after each character. The input of sed will be piped out to foo.
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
The Following User Says Thank You to nixcraft For This Useful Post:
raj (08-07-2009)
  #3 (permalink)  
Old 08-07-2009, 11:09 AM
raj's Avatar
raj raj is offline
Senior Member
User
 
Join Date: Jun 2005
Location: Hyderabad
OS: Fedora, Debian Linux
Posts: 307
Thanks: 42
Thanked 8 Times in 8 Posts
Rep Power: 6
raj will become famous soon enough raj will become famous soon enough
Default

thanks! worked like a charm!!
__________________
Raj
Linux rulz.
I have never turned back in my life ; I shall not do so today.. haha
Reply With Quote
Reply

Tags
pipe , pipes , sed , sed blank add blank , shell pipes


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Shell script that create a blank file in all sub-directories. samengr Shell scripting 3 17-02-2009 08:35 PM
Sed Insert Text Between Two Words LinuxCommandos Shell scripting 1 06-11-2008 05:16 PM
Binary Conversion Of Shell Script (shell script compiler) chandanperl Shell scripting 3 29-07-2008 10:22 AM
Change character set of a file Debug Linux software 0 15-05-2008 05:57 PM
insert user using CSV files gthian Shell scripting 1 24-09-2007 08:15 PM


All times are GMT +5.5. The time now is 06:13 AM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38