Split text in all chars


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Split text in all chars
# 1  
Old 06-29-2009
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 11:09 AM.. Reason: added code tags
# 2  
Old 06-29-2009
sed can do that..
Code:
/home/>echo "Hello World"|sed 's/\(.\)/\1\
/g';


Last edited by vidyadhar85; 06-29-2009 at 07:05 PM..
# 3  
Old 06-29-2009
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  
Old 06-29-2009
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  
Old 07-01-2009

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  
Old 07-02-2009
Try...
Code:
$ echo "Hello World"|fold -1
H
e
l
l
o

W
o
r
l
d

# 7  
Old 07-02-2009
hmm not working for me..
Code:
home> echo "hello world"|fold -1
fold: Not a recognized flag: 1
Usage: fold [-bs] [-w Width] [File...]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to split data with a delimiter having chars and special chars

Hi Team, I have a file a1.txt with data as follows. dfjakjf...asdfkasj</EnableQuotedIDs><SQL><SelectStatement modified='1' type='string'><! The delimiter string: <SelectStatement modified='1' type='string'><! dlm="<SelectStatement modified='1' type='string'><! The above command is... (7 Replies)
Discussion started by: kmanivan82
7 Replies

2. Shell Programming and Scripting

Split the text file into two

OS : RHEL 7.3 I have a file like below. I want to move (cut and paste) the first 7 lines of file1 to another file (file2). How can I do this ? In my real life scenario, I will be moving first 12 millions lines of file1 to file2 $ cat file1.txt 7369|SMITH |CLERK | ... (5 Replies)
Discussion started by: kraljic
5 Replies

3. Shell Programming and Scripting

Split a text file into multiple text files?

I have a text file with entries like 1186 5556 90844 7873 7722 12 7890.6 78.52 6679 3455 9867 1127 5642 ..N so many records like this. I want to split this file into multiple files like cluster1.txt, cluster2.txt, cluster3.txt, ..... clusterN.txt. (4 Replies)
Discussion started by: sammy777
4 Replies

4. Shell Programming and Scripting

XML - Split And Extract String between Chars

Hi, I am trying to read the records from file and split into multiple files. SourceFile.txt <?xml version="1.0" encoding="UTF-8"?>... (2 Replies)
Discussion started by: unme
2 Replies

5. Shell Programming and Scripting

Removing rows and chars from text file

Dear community, maybe I'm asking the moon :rolleyes:, but I'm scratching my head to find a solution for it. :wall: I have a file called query.out (coming from Oracle query), the file is like this: ADDR TOTAL -------------------- ---------- TGROUPAGGR... (16 Replies)
Discussion started by: Lord Spectre
16 Replies

6. Shell Programming and Scripting

Split text into paragraphs

Hi all! I want to make a code to split sentences into paragraphs maybe 4-5 sentences into one <p>text</p> there are no new lines in the text string any ideas with AWK, SSH? Thank you! (5 Replies)
Discussion started by: sanantonio7777
5 Replies

7. Shell Programming and Scripting

Split text file

Hi all, I am very new to shell scripting and some help is greatly appreciated. I have 10 column based text files, i would like to split each of them into 6 files ; the 1st one having columns 1, 2 ,3,4 , the second one having columns 1,2,8,9 etc. Is there a way I could get 60 files out my... (3 Replies)
Discussion started by: shreymuk
3 Replies

8. Shell Programming and Scripting

regex to remove text before&&after comma chars

Hi, all: I have a question about "cleaning up" a huge file with regular expression(s) and sed: The init file goes like this: block1,blah-blah-blah-blah,numseries1,numseries2,numseries3,numseries4 block2,blah-blah-blah-blah-blah,numseries,numseries2,numseries3,numseries4 ...... (3 Replies)
Discussion started by: yomaya
3 Replies

9. Shell Programming and Scripting

find 4 chars on 2nd line, 44 chars over

I know this should be simple, but I've been manning sed awk grep and find and am stupidly stumped :( I'm trying to use sed (or awk, find, etc) to find 4 characters on the second line of a file.txt 44-47 characters in. I can find lots of sed things for lines, but not characters. (4 Replies)
Discussion started by: unclecameron
4 Replies

10. Shell Programming and Scripting

How to convert C source from 8bit chars to 16bit chars?

I was using the following bash command inside the emacs compile command to search C++ source code: grep -inr --include='*.h' --include='*.cpp' '"' * | sed "/include/d" | sed "/_T/d" | sed '/^ *\/\//d' | sed '/extern/d' Emacs will then position me in the correct file and at the correct line... (0 Replies)
Discussion started by: siegfried
0 Replies
Login or Register to Ask a Question