Artificial intelligent assistant

Using || after awk ENVIRON replacement I'm using awk with a variable to cut log files based on a timestamp: LAST_LOG=$last_log awk 'index($0, ENVIRON["LAST_LOG"]) {y=1;next};y' $log_file ; If the date still exists in the log file it works, but if the log file was archived and replaced with a fresh file `awk` will fail. I want to fall back to `cat $log_file` if `awk` fails: LAST_LOG=$last_log awk 'index($0, ENVIRON["LAST_LOG"]) {y=1;next};y' $log_file ; \ || cat $log_file But this syntax returns `syntax error near unexpected token ||`. Is the line above not a normal function that I can use `&&` or `||` after?

The issue is `; ||` in


LAST_LOG=$last_log awk 'index($0, ENVIRON["LAST_LOG"]) {y=1;next};y' $log_file ; || cat $log_file


The `;` ends the `awk` invocation and the next command starts with `||`, which is a syntax error.

What you want to do is to check whether `y` is not 1 at the end of parsing the log file, and in that case make `awk` return a non-zero exit status:


LAST_LOG="$last_log" awk '
index($0, ENVIRON["LAST_LOG"]) { y = 1; next }
y { print }
END { exit !y }' <"$log_file" || cat <"$log_file"


Without the explicit `exit` you will only get a non-zero exit status out of `awk` if some sort of error occurred.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy bfcadc0cd5b96761359718af862f4415