Consider the following file called dates.txt containing some dates in US format, some of them palindromes (i.e., words that read the same backwards and forwards) and some not:
02/02/2020 03/02/2030 12/02/2021 06/19/1960 01/10/2010 03/07/2100
Write a one-line sed command that prints out only the lines containing date palindromes so that after running the appropriate sed command, the following would be output to the terminal:
02/02/2020 03/02/2030 12/02/2021
Here, I will use
-E option so that I don't have to escape parenthesis and sed command looks better. In the question, it is mentioned to print the dates that are in palindrome for a date to become palindrome the day and the month must be written in the reverse order in place of year.
p command is used for printing the words along with
-n option to suppress unnecessary lines.
$sed -E -n '/([0-9])([0-9])\/([0-9])([0-9])\/\4\3\2\1/p' dates.txt