Help with awk stmt

Hi All,

I have a log file as:

cat error.log.tmp1
2010-07-06 23:18:34 Connection Available to xyztestftp.abc.com.my
2010-07-06 23:20:33 Connection Available to xyztestftp.abc.com.my
ERROR FTP LOGIN

Now I am reading this complete log file if no single occurrence of word "ERROR" (this word if any will be the 1st word of the line only) then need to move a file to file.done otherwise do nothing.

For this I am using below code:

awk '/ERROR/{ if ($1 !~ /ERROR/) mv s s.done }' error.log.tmp1

But its not working can anyone tell me what is wrong?

Please help.

Thanks

You are doing it wrong :wink:

awk '/^ERROR/{x=1}END{if (x!=1) system("mv "FILENAME" "FILENAME".done")}' logfile

Tried this:

awk '/^ERROR/{x=1}END{if (x!=1) system("mv "s" "s"."done"")}' error.log.tmp1

But getting this:

Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
       mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
       mv [-f] [-i] [-e warn|force|ignore] d1 d2

And even the file is also not getting moved to .done.

Why are you altering that code? Why did you substitute "FILENAME" with "s"? Just change name of the file at the end of the command, and leave rest of the code the way it is.

awk '/^ERROR/{x=1}END{if (x!=1) system("mv "FILENAME" "FILENAME".done")}' error.log.tmp1

Edit: I missed parenthese at the end.

Thanks :b: got it working now.

awk '/^ERROR/{x=1}END{if (x!=1) system("mv s s.done")}' error.log.tmp1

---------- Post updated at 09:34 AM ---------- Previous update was at 09:01 AM ----------

Instead of hard coded file names if I am using variable i.e.

awk '/^ERROR/{x=1}END{if (x!=1) system("mv $file $file.done")}' 
error.log.tmp1

then getting this:

Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
       mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
       mv [-f] [-i] [-e warn|force|ignore] d1 d2
awk -vfile=$file '/^ERROR/{x=1}END{if (x!=1) system("mv "file" "file".done")}' error.log.tmp1
1 Like