O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Checking palindrome strings with a script

Checking whether a string is palindrome is one of the first lab exercises in a C programming course. However, here we have included this recipe to give you an idea of how to solve similar problems in which pattern matching can be extended in a way that previously occurring patterns repeat in the text.

Getting ready

The sed command has the capability to remember a previously-matched sub pattern. It is called back referencing. We can solve palindrome problems by using back referencing. We can solve this using multiple ways in Bash.

How to do it...

sed can remember previously matched regular expression patterns, thereby we can identify whether duplicates of a character exists in a string. This capability to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required