Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I use a filter to display something like:

echo "Hello there" |

H
e
l
l
o

t
h
e
r
e
share|improve this question
add comment

3 Answers

Here's a couple:

  1. fold

    echo "Hello there" | fold -w 1
    H
    e
    l
    l
    o
    
    t
    h
    e
    r
    e
    
  2. Perl

    echo "Hello there" | perl -pe 's/(.)/$1\n/g;'
    H
    e
    l
    l
    o
    
    t
    h
    e
    r
    e
    
share|improve this answer
    
+1 for constructive answer –  Lorenzo Von Matterhorn Mar 27 '13 at 14:43
    
The post was edited, I meant to make it display one letter in one line? –  Jurgen Malinao Mar 27 '13 at 14:44
    
@Znau thanks, unfortunately it was not what the OP wanted :). There was a formatting issue with their question. Fixed now, –  terdon Mar 27 '13 at 14:45
    
@JurgenMalinao, yes I edited it. If I correctly understood what you meant, the updated answer should do it. –  terdon Mar 27 '13 at 14:45
    
@terdon indeed, it was edited. still, i keep my comment :) –  Lorenzo Von Matterhorn Mar 27 '13 at 14:46
add comment

You can use sed to do this. It's a little more lightweight than perl but still allows you to use regular expressions to express your heart's desires.

$ echo "Hello world" | sed -r 's/./&\n/g'
H
e
l
l
o

w
o
r
l
d
share|improve this answer
    
Ah, I was just about to write the sed one :). fold will be the fastest though since it has no regex to deal with. –  terdon Mar 27 '13 at 14:47
    
@terdon And you earned an upvote from me. Took a minute to hunt down the & backreference; I don't use sed for this kind of things very often. (I doubt something like this would be performance critical in any case, however.) –  Michael Kjörling Mar 27 '13 at 14:49
add comment

This also works:

echo "Hello there" | grep -o .
  • . matches a single character.
  • -o only prints the match (rather than the whole line).
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.