Help with awk stmt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk stmt
# 1  
Old 07-06-2010
Help with awk stmt

Hi All,

I have a log file as:

Code:
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:

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
# 2  
Old 07-06-2010
You are doing it wrong Smilie
Code:
awk '/^ERROR/{x=1}END{if (x!=1) system("mv "FILENAME" "FILENAME".done")}' logfile


Last edited by bartus11; 07-06-2010 at 02:02 PM.. Reason: missed parenthese
# 3  
Old 07-06-2010
Tried this:

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

But getting this:

Code:
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.
# 4  
Old 07-06-2010
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.
Code:
awk '/^ERROR/{x=1}END{if (x!=1) system("mv "FILENAME" "FILENAME".done")}' error.log.tmp1

Edit: I missed parenthese at the end.
# 5  
Old 07-06-2010
Thanks Smilie got it working now.

Code:
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.

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

then getting this:

Code:
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

# 6  
Old 07-06-2010
Code:
awk -vfile=$file '/^ERROR/{x=1}END{if (x!=1) system("mv "file" "file".done")}' error.log.tmp1

This User Gave Thanks to bartus11 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

How to use a case stmt in a for loop?

How can I merge the move statements with the "FOR" loop to do a move of a file right after it zips it and not wait until all of the files are zipped to move all outisde the for loop. Here is my current code: for file in `ls -rt $svdumpdir/* | grep -v '.gz$' | grep '.gtt$' ` do echo... (8 Replies)
Discussion started by: mrn6430
8 Replies

2. Shell Programming and Scripting

How to use GOTO stmt in Unix scripting?

my code does somthing like this: #!bin/ksh sqlplus / | While read id do temp=`echo $id` i = i+1 done j=0 while do --connecting to sql and executing a Stored proc for 1st id --checking for the status status = $? if error --need to... (1 Reply)
Discussion started by: RP09
1 Replies

3. Shell Programming and Scripting

Case Stmt - Need Help Urgently

Hello All, Need help urgently.. i have a scenario where i have two files 1) mireport_20111406.txt 2) PRLIHSP01_8080.2011-06-11-15_26_31 ---------- I want a query something similar to this algorithm :- Case when file_name is like mireport then extract_date=14-06-2011 when... (4 Replies)
Discussion started by: iamnoone
4 Replies

4. Shell Programming and Scripting

Problem comparing String using IF stmt

Hi frnds Im facing an issues while trying to compare string using IF stmt, my code is: chkMsgName=`Service Fee Detail` if then if then if then echo "Valid File Ready for processing" fi fi ... (5 Replies)
Discussion started by: balesh
5 Replies

5. Shell Programming and Scripting

Help with Dates and SQl stmt?

hi All Please explain the below statement in RED?What does this mean? perl /HDS/common/operations/Quality_Team/Nirvana/WEEKLY_OOPS/sql_dump.pl --sql "select * from WEEKLY_REPORT order by test_case, type" --username=ddb_qa --password=ddb_qa123 --sid=pldeldb --output... (1 Reply)
Discussion started by: SVS_2017
1 Replies

6. Shell Programming and Scripting

if stmt argument expected error

CT=0 while read LINE do # Check to see if the LINE is non-empty, and has a <td> tag in it. if then # Increase the TD counter by 1 CT=`echo "$CT+1"` fi done <test.htmthrows this error: ksh: test: argument expected test.htm <tr> <td>text</td... (4 Replies)
Discussion started by: dba_frog
4 Replies

7. Shell Programming and Scripting

I want to get the Unix variable value in the sql stmt

Hi All I have a requirement where in I am stuck. There is a shell script that is being developed by me. It consist of the sql stmt also. I need to export a variable called HOMEPAGE with a value say www.abc.com. and then use this $HOMEPAGE variable in the sql stmt. My ultimate aim is to fetch all... (1 Reply)
Discussion started by: amitsinha
1 Replies

8. Programming

Function Returning Value w/o return stmt

I am working on a C/Unix application from last 2 years which communicates with other systems using proprietary format of my client. We have a function written in C which returns integer, which is response from other system to the request message initiated by my system. This return value is then... (1 Reply)
Discussion started by: dpmore
1 Replies

9. UNIX for Dummies Questions & Answers

Please explain the stmt

hi, Please explain the below stmt. P=1234 var1=:/a/b/c/file.dat printf "%s %s\n" "$" "${var1#?}" Output is: 1234 /a/b/c/file.dat What is #? in printf stmt? by using that the first character( : ) of "var1" variable is not displayed in output. How is that? please explain.. ... (1 Reply)
Discussion started by: srilaxmi
1 Replies
Login or Register to Ask a Question