Print a horizontal word vertically.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print a horizontal word vertically.
# 1  
Old 03-13-2009
Print a horizontal word vertically.

Say I have the word:

zinger

I want to change it to print

z
i
n
g
e
r


This is for a sorting algorithm that I am testing out. I will then use sort on the vertical and change it back to horizontal printing using tr. Once it is horizontal again, I can compare that sorted jumble against a dictionary doing the same munging. It should give me all the words that use the same letters with the same frequency.

Unfortunately, I am having a brain fart and can't figure out how to get sed to convert this from horizontal to vertical.

I tried this:

sed -e 's/(.)/\1\n/g'

but it doesn't work. It says that my back reference on the right hand side is wrong.

Any help would be appreciated.

Jim
# 2  
Old 03-13-2009
one way:
Code:
#!/bin/ksh

printf $(echo '1234' | sed 's/./&\\n/g' )

# 3  
Old 03-13-2009
Code:
echo 'zinger' | sed 's/./&\
/g'

# 4  
Old 03-13-2009
Code:
echo zinger | awk '{gsub(".","&\n");printf "%s",$0}'

# 5  
Old 03-13-2009
Code:
echo zinger | nawk '{gsub(".","&\n")}1' ORS=

# 6  
Old 03-13-2009
Code:
# echo "zinger" | fold -b1
z
i
n
g
e
r

# 7  
Old 03-16-2009
Quote:
Originally Posted by ghostdog74
Code:
# echo "zinger" | fold -b1
z
i
n
g
e
r

@Ghostdog, fold -b1 will throw the below error:

Code:
#  echo "zinger" | fold -b1
fold: illegal option -- 1
Usage: fold [-bs] [-w width | -width ] [file...]

The correct usage is:

Code:
# echo "zinger" | fold -bw 1
z
i
n
g
e
r


Regards,

Praveen
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Print vertical to horizontal

Hi Masters, I need help to change my vertical data to horisontal input 2015-04-13|JS|741667 2015-04-13|JSJ|2272 2015-04-13|TMS|107099 2015-04-12|JMD|47945 2015-04-13|TM|760024 2015-04-13|JM|484508 2015-04-14|JMJ|318 2015-04-14|JSD|54436 2015-04-13|JM|15410 Output... (2 Replies)
Discussion started by: radius
2 Replies

2. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

3. Shell Programming and Scripting

[Solved] Search for a word and print the next word

Hi, I am trying to search for a word and print the next word. For example: My text is "<TRANSFORMATION TYPE ="Lookup Procedure">" I am searching for "TYPE" and trying to print ="Lookup Procedure" I have written a code like following: echo $line | nawk... (4 Replies)
Discussion started by: sampoorna
4 Replies

4. Shell Programming and Scripting

awk Help: Horizontal to Vertical print with pattern match

Hi AWK Experts, Following is the data : BRH113 DD AA HH CA DD DD AA HH BRH091 A4 A6 AH H7 67 HH J8 9J BRH0991 AA D8 C23 V5 H7 BR2 BRH991 AA HH GG5 BT0 JJ0 I want the output to be alligned with the pattern matching "BRH" inthe line. The output should be look like: A]... (4 Replies)
Discussion started by: rveri
4 Replies

5. Shell Programming and Scripting

perl lwp find word and print next word :)

hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this: I have in my response lines like: <div class="sender">mimi020</div> <some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies

6. Shell Programming and Scripting

How ti Grep for a word and print the next word

Hi can we grep for a word and print the next word of the greped word? ex:- create or replace function function_name create function function_name we should search for word "function" and output next word "function_name" from both lines. (3 Replies)
Discussion started by: manasa_vs
3 Replies

7. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

8. UNIX for Dummies Questions & Answers

Script to search for a particular word in files and print the word and path name

Hi, i am new to unix shell scripting and i need a script which would search for a particular word in all the files present in a directory. The output should have the word and file path name. For example: "word" "path name". Thanks for the reply in adv,:) (3 Replies)
Discussion started by: virtual_45
3 Replies

9. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

10. UNIX for Dummies Questions & Answers

How to print the word

1) I had one query regarding how to define a particular value which has a space. For example, I would say for i in s su sur do print $i sleep 1 done This will results in s su sur Now I want... (0 Replies)
Discussion started by: ss_psm
0 Replies
Login or Register to Ask a Question