How to reverse each word in a text file with linux commands without changing order of words -


there's lots of questions indicating how reverse each word in sentence, , readily in python or javascript example, how can linux commands? looks tac might option, seems reverse lines words, rather words? other tools can this? literally have no idea. know rev , tac , awk seem contenders...

so i'd go from:

cat dog sleep pillow green blue 

to:

tac god peels wollip neerg eulb 

**slight followup

from this reference looks use awk break each field array of single characters , write loop reverse manually each word in way. quite awkward. surely there's better/more succinct way this?

try on size:

sed -e 's/\s+/ /g' -e 's/ /\n/g' < file.txt | rev | tr '\n' ' ' ; echo 

it collapses space , counts punctuation part of "words", looks (at least mostly) works. hooray sh!


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -