new to linux/Ubuntu/shell scripting . . .
Tobias Heinemann
theine at nordita.dk
Mon Dec 5 21:39:30 UTC 2005
> Thanks, it looks like it was going for parts of words that where
> palindrome-like so I got some palindromes, but I need whole words. Am
> trying to tweak it so I get whole words that are palindromes (also
> using -i to ignore case), but not having luck yet.
Right, so an improved version would be
grep -o -E "(^|\ )([A-Za-z])([A-Za-z])\3\2($|\.|\ )" bigTextFile.txt
which will only match 4 letter palindromes that follow beginning of a
line or a whitespace and are themselves followed by end of a line, a
period, or a whitespace.
Having "[A-Za-z]" instead of just "[a-z]", this regex will match "anna",
"AnnA", "aNNa", and "ANNA", but not for instance "Anna", and the -i
switch won't help you with that I'm afraid.
Have you thought about using Perl or Python for this task? To my
understanding, these languages would be a good fit here.
> What does -o mean?
By default, grep prints out whole lines containing the matching regex,
the -o switch makes it print out only the matching part of the line.
Hint: man grep
Regards,
Tobi
More information about the ubuntu-users
mailing list