Here's some general advice:
QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS
. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
Assuming you're using bash, it's recommended to use ((..))
for numerical tests, and [[..]]
for string tests and other complex expressions. Don't use the old [..]
test unless you specifically need POSIX-style portability.
command syntax is:
printf '<format>' input input input
Where the <format> is any text string you want, with "%x
"-style parameters inserted wherever you want the input strings to appear. Ideally you should have one parameter for each input value, but printf will operate as many times as necessary to consume all the inputs.
" is equivalent to echo
, for example.
So if you only want to print the raw string, followed by a newline, then just use echo. For fancier layout work, learn how to use printf's format strings.
has a "-c
" option for directly counting the number of matching lines. No need to use a text file and wc
. And even if you wanted to use wc, you could still skip the file and pipe the output of grep directly into it.
And no matter what, the "a" file and awk
read appear to be completely superfluous.
grep -ic 'remark c' test.eel1
grep -i 'remark c' test.eel1 | wc -l