The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regex to remove text before&&after comma chars yomaya Shell Programming and Scripting 3 06-08-2009 05:44 AM
How to split a text after fix character count vikash.rastogi Shell Programming and Scripting 5 10-23-2008 06:32 PM
efficiently split a 2GB text file into two ihot Shell Programming and Scripting 2 10-15-2007 05:25 PM
How to convert C source from 8bit chars to 16bit chars? siegfried Shell Programming and Scripting 0 09-26-2007 02:26 PM
Split text file by pages ranri UNIX for Dummies Questions & Answers 2 06-01-2001 02:43 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-29-2009
WSyS WSyS is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
Split text in all chars

Hello,

I need a shell script to split a text to all chars. The text is:
Code:
Hello World
But i need it:
Code:
H
e
l
l
o
 
W
o
r
l
d

Last edited by Yogesh Sawant; 07-05-2009 at 10:09 AM.. Reason: added code tags
  #2 (permalink)  
Old 06-29-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
sed can do that..
Code:
/home/>echo "Hello World"|sed 's/\(.\)/\1\
/g';

Last edited by vidyadhar85; 06-29-2009 at 06:05 PM..
  #3 (permalink)  
Old 06-29-2009
WSyS WSyS is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 2
echo "Hello World"|sed 's/\(.\)/\1\> /g';
H
> e
> l
> l
> o
>
> W
> o
> r
> l
> d
>



How can i remove this ">" ?

---------- Post updated at 04:38 PM ---------- Previous update was at 04:36 PM ----------

echo "Hello World"|sed 's/\(.\)/\1\/g';



OK thank you it works!
  #4 (permalink)  
Old 06-29-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,426
GNU awk
Code:
# echo "Hello World" | awk 'BEGIN{FS=""}{for(i=i;i<=NF;i++)print $i}'
Hello World
H
e
l
l
o

W
o
r
l
d
  #5 (permalink)  
Old 07-01-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,319

The shell can do it without any external commands:

Code:
string="Hello World"
while [ -n "$string" ]; do
  printf "%c\n" "$string"
  string=${string#?}
done
  #6 (permalink)  
Old 07-02-2009
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,402
Try...
Code:
$ echo "Hello World"|fold -1
H
e
l
l
o

W
o
r
l
d
  #7 (permalink)  
Old 07-02-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
hmm not working for me..
Code:
home> echo "hello world"|fold -1
fold: Not a recognized flag: 1
Usage: fold [-bs] [-w Width] [File...]
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On



All times are GMT -4. The time now is 11:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0