Code:
1 find ./ -type f -print | while read LINE;
2 do
3 if [ x`echo ${LINE%.*} | grep "[kl]$"` != "x" ]; then
4 echo $LINE;
5 fi;
6 done
To help me explain it, I have broken it up into multiple lines and numbered them. This is actually a very small bourne shell script. I gave it as one line to avoid even more confusion. I am going to use the numbers to help explain things. They are not part of the real thing and they are a little arbitrary... I could have numbered them differently if I had laid them out differently.
Line 1: find ./ -type f -print | while read LINE
This bit of code finds all the regular files under the current directory. It then pipes them (|) to a while loop... which stores each line in a variable called LINE. This essentially feeds the actual work part of the program.
Line 2: do
This is the start of our loop. We are going to do all the following steps to each line produced by find above.
Line 3a: `echo ${LINE%.*} | grep "[kl]$"`
The code ${LINE%.*} finds and removes the shortest suffix it can, matching the pattern ".*" which removes any extension. This is where the magic actually happens. The result of the first bit is fed into a grep to see if the end of the line ($) is a k or an l ([kl]).
Line 3b: if [ x` ... ` != "x" ]; then
The 3a bit leaves a string in the if test, if there was a match. So for example, "if [ xtook != x ]; then" would be the test being evaluated and would be true. If there was no match... it would be an empty string and x would equal x so the body of the if loop would not be executed. "!=" tests to ensure that the strings are not equal.
Line 4: echo $LINE;
If the above if test was true, we print out $LINE... which was the name of the file found by find.
Line 5: fi
This closes out if test.
Line 6: done
This signifies the end of our while loop that started with do above... well really started with the while code itself but structurally was wrapped with do and done.
I hope this helped make a little sense of it.