[wellylug] a bit of awk

Jonny Robertson jonny at prophecy.net.nz
Mon Mar 22 15:45:03 NZST 2004


I think your logic is a bit broken.
With the code below you will end up executing the find /home command 
again for each 'hit' in the original find.

Also, I'm fairly sure awk's internal variable space is quite seperate 
from bash's (or any other shells) variable space.

So maybe try something along the lines of:

  for nom_file in `find /home -path '*.doc'`;
  do
    location=`echo $nom_file | awk --field-separator=/ '{ print $3 }'`
    etc.

-jonny

E.Chalaron wrote:
> Hi there
> 
> I am writing my first script with awk 
> I'd like to assign a field value returned by awk to $location
> 
> Of course the following does not work... though the line 
> find -path '*.doc' | awk --field-separator=/ '{print $3}' 
> 
> displays the proper value.
> 
> Any help somebody ?
> Thanks a lot
> Edouard
> 
> #!/bin/bash
>  IFS=$(echo -e "\n\r\t")
>  for nom_file in `find /home -path '*.doc'`;
>  do
>      find /home -path '*.doc' | awk --field-separator=/ '{$3}'=$location
>      catdoc "${nom_file}" > "/home/$location/$(basename ${nom_file} .doc).txt"
>  done
> 
> 


-- 

Jonny Robertson
Security Engineer
Prophecy Networks Ltd
+64 21 890505




More information about the wellylug mailing list