new to linux/Ubuntu/shell scripting . . .

Rachael C. amaroq3 at gmail.com
Mon Dec 5 21:51:57 UTC 2005


ok, hmm to work around not being able to find Anna, can I change all
the text in bigTextFile to lowercase, and then do the search?  If so,
how would I go about doing that?

On 12/5/05, Tobias Heinemann <theine at nordita.dk> wrote:
>  > 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
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> http://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>




More information about the ubuntu-users mailing list