I have a column, with some words:
scatman
batman
superman
scatman
scatman
batman
superman
scatman
scatman
batman
superman
scatman
batman
WWWWWWWW
superman
scatman
batman
superman
scatman
I should make some patterns, where i need to have word by word three words: scatman, batman, superman. Where, i have repeat words, like scatman & scatman on line 4 & 5 or where i have other words, i should cut them I have written:
grep "scatman\|batman\|superman" file
Ok, i have rejected word WWWWWWWW, but i can't understand how to show my column word by word. Ihave in result:
scatman
batman
superman
scatman
scatman
batman
superman
scatman
scatman
batman
superman
scatman
batman
superman
scatman
batman
superman
scatman
At line 4 & 5 i have repeat words, but i don't like that. Where i have the mistake ?
This will do exactly as you want
Will print out every word on a new line like this:
or on a one line like this:
This can be done with
grep
andawk
:The
grep -E
allows an extended Regular Expression that lets you use|
as anor
for search targets. Theawk
code looks for repeated words and skips them.You can do all this in one line, if you want to: