I have made a program that reads a text file and checks for palindromic words and then outputs them. They each appear on a new line with a count of the number of occurences beside each of the words.
Requirements for being classed as palindrome are that the word must have at least 3 letters and at least 2 of them must be different. For example, eee would not be a palindrome but eye would be.
I am having a problem in that my program is picking up some of the words such as eee and iii. I have added the grep command highlighted below to try and fix this but I keep coming up against these errors. I cannot seem to get it to work.
./palindrome: line 5: syntax error near unexpected token `|'
./palindrome: line 5: ` | grep -P -v '^(.)\1*$''
Can you explain the real-life application for this script? While posted in a general area, this appears similar to a school project or homework assignment. If it is a school/homework assignment, please repost in that section.
From the error message you're getting from grep , one might guess that you're using a macOS or BSD operating system, but I don't see why you would get a syntax error on line 5 from bash with this code on those systems.
One might also guess that you copied this code from someone who was using a different operating system that has a grep utility that has a -P option. (The 2nd error message you're getting says that the grep utility you're using does not have a -P option.)
So, where did you get this code and what operating system was being used by the person who wrote this code? And, what operating system and shell are you using?
If you change the grep to get rid of the unknown option and convert the RE being used to be one that would be accepted by any standard version of grep :
grep -v '^\(.\)\1*$'
you have a grep command that will delete lines where every character in a word is the same character and there are at least two characters in the word.
Making the huge assumption that the shell you're using understands the <(command) syntax in addition to standard shell file redirections, your script with the above modification seems to do what you want.