Here is one way: GNU awk and rev
Run as:
awk -f ./script.awk <(echo "hello" | cowsay){,} | rev
The content of script.awk :
FNR==NR { if (length > max) { max = length } next } { while (length < max) { $0=$0 OFS } }1
Alternatively, here is a single line:
awk 'FNR==NR { if (length > max) max = length; next } { while (length < max) $0=$0 OFS }1' <(echo "hello" | cowsay){,} | rev
Results:
_______ > olleh < ------- ^__^ \ _______\)oo( \ \/\) \)__( | w----|| || ||
----------------------------------------------- --- --------------------------------------------
Here's another way to use GNU awk :
Run as:
awk -f ./script.awk <(echo "hello" | cowsay){,}
The content of script.awk :
BEGIN { FS="" } FNR==NR { if (length > max) { max = length } next } { while (length < max) { $0=$0 OFS } for (i=NF; i>=1; i--) { printf (i!=1) ? $i : $i ORS } }
Alternatively, here is a single line:
awk 'BEGIN { FS="" } FNR==NR { if (length > max) max = length; next } { while (length < max) $0=$0 OFS; for (i=NF; i>=1; i--) printf (i!=1) ? $i : $i ORS }' <(echo "hello" | cowsay){,}
Results:
_______ > olleh < ------- ^__^ \ _______\)oo( \ \/\) \)__( | w----|| || ||
----------------------------------------------- --- --------------------------------------------
Explanation:
Here is an explanation of the second answer. I take basic knowledge of awk :
FS=""
Some other things you might need:
The wildcard {,} is an abbreviation for repeating the input file name twice. Unfortunately, this is not a standard Bourne shell. However, you can use instead:
<(echo "hello" | cowsay) <(echo "hello" | cowsay)
In addition, in the first example, { ... }1 is short for { ... print $0 }
NTN.