assigning commands to a variable
I'm having trouble with a shell script I wrote that parses through logs using awk and tail's "follow" option. I wanted to add an optional argument to search (using grep), and I'm having trouble.
Code:
if [ "$1" = "--logger" ] |
Don't know if this will fix it, but. You have two if statments and only one fi. The script should crash instead of run: unmatched if error. The usual syntax is:
if (something); then (do something) elif (do something else) fi |
I have the "fi" in there. It's just on the other side of a huge awk script (hence the "...").
|
You can bypass the problem, for example :
Code:
if [ "$1" = "--logger" ] Another possibility would be to integrate the second filter into the awk script. |
I actually really like the idea of sticking the awk script in its own file. That worked well. Now my code appears as...
Code:
<clip> if [ "$2" ] It should be possible for me to work the search into the awk script by making it 'next' if it doesn't see the search string in each iteration, but I'm not sure how to do that. I know you can use something like "/[^a-zA-Z]/" to exclude anything that has letters, but I'm not sure how to go about doing the same thing with a string. |
Hah, I guess I should try the obvious first. I made it work by just parsing each line and using index() to see if the search value is there. The search string is passed to awk through the -v declaration and is set to "" if left blank.
Code:
BEGIN { |
All times are GMT -5. The time now is 07:57 AM. |