Author Topic: AWK  (Read 2818 times)

Phoenix

  • Guest
AWK
« on: November 10, 2004, 10:16:09 am »
Well, now I'm writing a script in which a parameters file needs to be read.
the parameter file is  ; delimited, it looks like this:

field1;field2;field3;field4;field5;field6;field7
field1;field2;field3;field4;field5;field6;field7
field1;field2;field3;field4;field5;field6;field7

Now when I run the next command:

   cat ${PARFILE} | grep -v "^\#" | while read PARAMETERS
   do
      awk -F";" {'print $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7'} $PARFILE
   done
   ....

the files will be read and displayed on the screen..

But now I want to set   A   to the values of $1
B = $2
C = $3
etc

how can i fix this the best way??
...
awk -F";" {"A= $1" "B = $2" "C = $3" "D = $4" "E = $5" "F = $6" "G = $7"} $PARFILE
...
echo "$A"
echo "$B"
...

seems not to work... whatever I try with this I get a
awk: syntax error near line 1
awk: illegal statement near line 1

when I try:
...
awk -F";" {' "A = $1" "B = $2" "C = $3" "D = $4" "E = $5" "F = $6" "G = $7"'} $PARFILE
...
echo "$A"
echo "$B"
...
echo "TEST"

I get some empty lines, and then TEST.


what is the correct syntax of giving the values thorugh to the variables???

Note: $PARFILE is set to the path and filename of the parameters file.
« Last Edit: November 10, 2004, 10:47:52 am by Phoenix »

Phoenix

  • Guest
Re:AWK
« Reply #1 on: November 10, 2004, 02:38:25 pm »
ok an update allready...

This is the script I ran...

#!/usr/bin/ksh
#set -x
DATE=`date +%Y'-'%m'-'%d' '%H':'%M':'%S`
PARFILE=/export/home/hochster/ov/parameters.lst
OV_LOGDIR=/var/log/vcs_ov

cat ${PARFILE} |grep -v "^\#" | while read PARAMETERS
do
   awk -F";" {'print $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7'} $PARFILE
   LOGDIR=`awk -F";" {'print $1'} $PARFILE`
   SYNTAX=`awk -F";" {'print $2'} $PARFILE`
   SEVERITY=`awk -F";" {'print $3'} $PARFILE`
   MSGGRP=`awk -F";" {'print $4'} $PARFILE`
   TAIL=`awk -F";" {'print $5'} $PARFILE`
   ERRORCODE=`awk -F";" {'print $6'} $PARFILE`
   MSGTXT=`awk -F";" {'print $7'} $PARFILE`

echo "$LOGDIR"
echo "$SYNTAX"
echo "$SEVERITY"
echo "$MSGGRP"
echo "$TAIL"
echo "$ERRORCODE"
echo "$MSGTXT"
echo "$DATE"
echo "$PARFILE"
echo "$OV_LOGDIR"
echo "-----------------------------"

done

The file parameters.lst contains:
hochster@svradm03> more parameters.lst
/var/log/httpd/acces.log;ERROR;Major;VCS_OPS;500;lg0001;doet t niet;
/var/log/builds/web/web.log;ERROR;Critical;VCS_OPS;500;lg0002;doet t ook nie;
/var/log/builds/web/web.log;ERROR;Critical;VCS_OPS;500;lg0002;doet t ook nie;

When the script is finished, I get:
hochster@svradm03> ./parm.sh
/var/log/httpd/acces.log ERROR Major VCS_OPS 500 lg0001 doet t niet
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/httpd/acces.log
/var/log/builds/web/web.log
/var/log/builds/web/web.log
ERROR
ERROR
ERROR
Major
Critical
Critical
VCS_OPS
VCS_OPS
VCS_OPS
500
500
500
lg0001
lg0002
lg0002
doet t niet
doet t ook nie
doet t ook nie
2004-11-10 14:35:07
/export/home/hochster/ov/parameters.lst
/var/log/vcs_ov
-----------------------------
/var/log/httpd/acces.log ERROR Major VCS_OPS 500 lg0001 doet t niet
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/httpd/acces.log
/var/log/builds/web/web.log
/var/log/builds/web/web.log
ERROR
ERROR
ERROR
Major
Critical
Critical
VCS_OPS
VCS_OPS
VCS_OPS
500
500
500
lg0001
lg0002
lg0002
doet t niet
doet t ook nie
doet t ook nie
2004-11-10 14:35:07
/export/home/hochster/ov/parameters.lst
/var/log/vcs_ov
-----------------------------
/var/log/httpd/acces.log ERROR Major VCS_OPS 500 lg0001 doet t niet
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/httpd/acces.log
/var/log/builds/web/web.log
/var/log/builds/web/web.log
ERROR
ERROR
ERROR
Major
Critical
Critical
VCS_OPS
VCS_OPS
VCS_OPS
500
500
500
lg0001
lg0002
lg0002
doet t niet
doet t ook nie
doet t ook nie
2004-11-10 14:35:07
/export/home/hochster/ov/parameters.lst
/var/log/vcs_ov
-----------------------------

Wanted result:
/var/log/httpd/acces.log ERROR Major VCS_OPS 500 lg0001 doet t niet
/var/log/httpd/acces.log
ERROR
Major
VCS_OPS
500
lg0001
doet t niet
2004-11-10 14:35:07
/export/home/hochster/ov/parameters.lst
/var/log/vcs_ov
-----------------------------
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/builds/web/web.log
ERROR
Critical
VCS_OPS
500
lg0002
doet t ook nie
2004-11-10 14:35:07
/export/home/hochster/ov/parameters.lst
/var/log/vcs_ov
-----------------------------
/var/log/builds/web/web.log ERROR Critical VCS_OPS 500 lg0002 doet t ook nie
/var/log/builds/web/web.log
ERROR
Critical
VCS_OPS
500
lg0002
doet t ook nie
2004-11-10 14:35:07
/export/home/hochster/ov/parameters.lst
/var/log/vcs_ov
-----------------------------
« Last Edit: November 10, 2004, 02:44:52 pm by Phoenix »

Phoenix

  • Guest
Re:AWK
« Reply #2 on: November 11, 2004, 04:16:45 pm »
#!/usr/bin/ksh
#set -x
DATE=`date +%Y'-'%m'-'%d' '%H':'%M':'%S`
PARFILE=/export/home/hochster/ov/parameters.lst
OV_LOGDIR=/var/log/vcs_ov

#cat ${PARFILE} |grep -v "^\#"
grep -v "^\#" $PARFILE > tempfile
awk -F";" {'print $1 " " $2 " " $3 " " $4 " " $5 " " $6 " " $7'} tempfile >tempf
ile2
while read LOGDIR SYNTAX SEVERITY MSGGRP TAIL ERRORCODE MSGTXT
do
echo "$LOGDIR"
echo "$SYNTAX"
echo "$SEVERITY"
echo "$MSGGRP"
echo "$TAIL"
echo "$ERRORCODE"
echo "$MSGTXT"
echo "$DATE"
echo "$PARFILE"
echo "$OV_LOGDIR"
echo "-----------------------------"


done <tempfile2


thats it... thanks for the help ;)

Offline gryphon

  • Just me...
  • Administrator
  • Manager
  • *****
  • Posts: 1.733
  • nothing can seem fool to those that winn. ...
Re:AWK
« Reply #3 on: November 11, 2004, 08:09:38 pm »
so I lend you a book and this is the result ?

and you're welcome..... ;)
Expect anything, and life will become boring...

Phoenix

  • Guest
Re:AWK
« Reply #4 on: November 12, 2004, 09:07:29 am »
no, this is now just a funtion... the script isnt fixed by far...
so.... this is part 1 of 10  i think...