trying to call awk from within a shell script 
Author Message
 trying to call awk from within a shell script

huge shell script that tries the following:

FILE1="/tmp/file1"
TMPFILE="/tmp/output"

awk 'BEGIN{
{
  if($0 ~ /set.*line/)
  {
     print "insert into triggers values ( 'Name','select * from db.tabe
where Event = 1 and Score = 0 and Severity <
3\;','','','','Action','',0,0,1,5,0,0,1,'This should not be this
hard.\r\n\r\nThe script is looking for the following:\r\n\r\n','Event =
1\r\nScore = 0\r\nSeverity < 3\r\n\r\nThis script fires an
action.','','',0,0 );";
  }

Quote:
}
 print;
}' $FILE1 > $TMPFILE

This does not work.  As is it gives an error trying to read in 3;... due to
the <.  Escaping the <'s gives a syntax error.  Escaping all the single
ticks give a ")" unexpected error.

The last line of file1 is "set recovery line", and the end goal is to append
the output of the print statement to file1 just before the last line.

Any ideas?

dj

______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.*-*-*.com/



Tue, 27 Jul 2004 11:00:34 GMT  
 trying to call awk from within a shell script

Quote:

>huge shell script that tries the following:

>FILE1="/tmp/file1"
>TMPFILE="/tmp/output"

>awk 'BEGIN{

The BEGIN{ } block is executed before reading the first line of input, so $0
is empty.

Quote:
>{
>  if($0 ~ /set.*line/)
>  {

In an if, for, while, or until statement, the opening brace { should be on
the same line.

Quote:
>     print "insert into triggers values ( 'Name','select * from db.tabe
>where Event = 1 and Score = 0 and Severity <
>3\;','','','','Action','',0,0,1,5,0,0,1,'This should not be this
>hard.\r\n\r\nThe script is looking for the following:\r\n\r\n','Event =
>1\r\nScore = 0\r\nSeverity < 3\r\n\r\nThis script fires an
>action.','','',0,0 );";
>  }
>}
> print;
>}' $FILE1 > $TMPFILE

>This does not work.  As is it gives an error trying to read in 3;... due to
>the <.  Escaping the <'s gives a syntax error.  Escaping all the single
>ticks give a ")" unexpected error.

In shell scripts, you can't use single quotes inside a single quoted string.
Some workarounds are:
awk '{print "'\''"}'
awk '{print "\047"}'
awk -f awkscript

Quote:
>The last line of file1 is "set recovery line", and the end goal is to
append
>the output of the print statement to file1 just before the last line.

awk '{print holdline;holdline=$0}
     END{print "this goes before the last line"; print holdline}'


Tue, 27 Jul 2004 15:16:20 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. shell commands within awk script

2. Shell variable within an awk script

3. calling shell editor within script

4. EXPECT : calling shell fns. from within expect script

5. Access to Script Name Within Awk Script

6. Invoking shell command from within awk

7. executing a shell command within AWK

8. Calling scripts from within scripts, is this possible?

9. Starting interactive shell/irb from within a script?

10. Problem with get exit status of shell script/command within expect

11. Shell commands from within a script

12. Replacing a string from an input file within awk script

 

 
Powered by phpBB® Forum Software