getting cowsay to send one word at a time in putty
This seems to be a rare case where word splitting is actually desirable:
for word in $(<file.txt); do cowsay "$word"; sleep 1; done
(the sleep
command is optional). Or there's always xargs
:
xargs -a file.txt -n1 cowsay
Here's something I came up with really quickly. I put one line in a test file then fed it to cowsay.
terrance@terrance-ubuntu:~$ cat cstest.txt
This is a test file to test cowsay
I set it to read each line, then do a for loop
of each line to read each word. Example below:
:~$ cat cstest.txt | while read line; do for word in $line; do cowsay $word; done; done
______
< This >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
____
< is >
----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
___
< a >
---
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______
< test >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______
< file >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
____
< to >
----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______
< test >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
________
< cowsay >
--------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Each individual line of that command would look like:
:~$ cat cstest.txt | while read line
>do
>for word in $line
>do
>cowsay $word
>done
>done
Hope this helps!
Python one-liner:
python -c 'import sys,subprocess;[subprocess.call(["cowsay",w]) for l in sys.stdin for w in l.split()]' < words.txt
Sample run:
$ cat words.txt
this is a test
$ python -c 'import sys,subprocess;[subprocess.call(["cowsay",w]) for l in sys.stdin for w in l.split()]' < words.txt
______
< this >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
____
< is >
----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
___
< a >
---
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
______
< test >
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
$