Reputation: 25
I want to process a paragraph using sed. I want to extract sentence with odd number of words only. and then print the words in reverse order. e.g: input is 'Hello world. hello world again.' and the output required 'again world hello'
Upvotes: 0
Views: 298
Reputation: 189618
If this is homework, your teacher wants you to discover sed's hold pattern. If this is not homework, it is much less awkward to do this in e.g. Perl. Welcome to the world of wonderful Perl one-liners:
perl -00 -lane 'next unless @F % 2; $, = " "; print reverse @F' yourfilenamehere
This only does paragraphs. Splitting into sentences and looping over those should not be too hard to hack in.
Upvotes: 1