The structural characteristics of the all-back text are as follows:
Assuming that the number of characters is even, it is structurally represented as a sequence of characters with the same character but with the opposite sequence of characters.
Assuming that the number of characters is odd, it is structurally represented as a sequence of characters with a character that is identical but in the opposite order, but the two sequences share one character in the middle.
The SED command remembers the previously matched sub-styles.
You can use the normal form: ' \ (. \) '. Match a random character. \1 represents its inverse reference. If you match a two-character wenzheng, the table is:
' \ (. \) \ (. \) \2\1 '
A palindrome script that matches a random length, as seen in the following:
#!/bin/bash#file Name:match_palindrome.sh#function:find palindrome in a file.if [$#-ne 2] thenecho "Usage: $ filenam E string_length "exit-1fifilename=$1basepattern= '/^\ (. \) ' count=$ (($2/2)) # Matche certain length for (I=1; i < $ Count i++)) dobasepattern= $basepattern ' \ (. \) ';d one# the length is evenif [$ ($ 2)-ne 0]thenbasepattern= $basepattern '. Fifor (count; count > 0; count--)) dobasepattern= $basepattern ' \ ' $count;d oneecho "debug: $basepattern" # Print the resultbasepattern= $basepattern ' $/p ' sed-n "$basepattern" $filename
Shell script implementation detects palindrome strings