loops - BASH Palindrome Checker -


This is my first posting, so please bear with me

I received a Bash Assignment but my professors are totally baseless and have their notes too.

Our assignment is to filter the slopes and print from a file. In this case, the directory is:

  / usr / share / dict / words  

The word length is from 3 to 45 and only considered this Filter lowercase letters (the given dictionary has letters and uppercase, as well as lowercase letters). That is, "kas-das" can be counted as something like "q-evvavve-q" as a palate but I should not get it as a proper result.

Anyway, I can get it to filter the volume and return of the x word (though not only the lowercase filter).

  grep "^ ... $" / usr / share / dict / words | Grep "\ (. \). 1"  

And I can use the following lines for words of 5 letters and 7 and above:

  grep "^ ..... $" / usr / share / words / words | Grep "\ (. \) \ (. \.). \ 2 \ 1"  

But the professor does not want that. We should use a loop I get the concept but I do not know the syntax, and like I said, these notes are very useless.

The one that I tried was setting the variable x = ... and y = .. and in a while, x = $ x $ y, but that (syntax error) did not work Nor x + = ..

Any help is appreciated. Even my non-lowercase letters are being filtered.

Thank you!

Edit:

If you are providing an indication for a solution or solution, the simplest method is preferred. Preferably one that uses 2 grep statements and a loop.

Thanks again

like this:

  for word `grep -E '^ [Az] {3,45} $ / / USD / share / word / word'; [$ Word == `echo the word $. Rev '] & amp; Amp; Echo $ word; done;  

Output using my dictionary:

  Aha bib Bob Bob ... wow  

< Strong> updates

As noted in the comments, reading in one of the variables in the loop can not be the most efficient, and there are no risks triggering errors in some shells. You can. Here is an updated version:

  grep -E '^ [a-z] {3,45} $' / usr / share / dict / words | While read -r word; [$ Word == `echo the word $. Rev '] & amp; Amp; Echo $ word; done;  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -