[wellylug] Re: a bit of awk / sh dumping value

Ewen McNeill wellylug at ewen.mcneill.gen.nz
Mon Mar 22 17:10:30 NZST 2004


In message <20040322045454.RRAP3651.mta1-rme.xtra.co.nz at there>, "E.Chalaron" wri
tes:
>> location=`find /home -path '*.doc' | awk --field-separator=/ '{$3}'`
>> catdoc "${nom_file}" > "/home/$location/$(basename ${nom_file} .doc).txt"
>
>I eventually figured it out. but without thinking that find will relist all 
>my files.

Ah, I should have looked more closely at the context instead of assuming
that you had basically everything right but the syntax for assiging to a
variable.

>IFS=$(echo -e "\n\r\t")
>for nom_file in `find /home -path '*.doc'`;
>do
>  expression to dump the value of nom_file into a file called /tmp/file.txt
>  location= awk --field-separator=/ '{$3}' /tmp/file.txt
>  echo $location #just to make sure
>  catdoc "${nom_file}" > "/home/$location/$(basename ${nom_file} .doc).txt"
>done

for nom_file in `find /home -path '*.doc'`; do
  location=$(echo "$nom_file" | awk --field-separator=/ '{$3}')
  catdoc "${nom_file}" > "/home/$location/$(basename ${nom_file} .doc).txt"
done

or even

for nom_file in $(find /home -path '*.doc'); do
  location=$(echo "$nom_file" | awk --field-separator=/ '{$3}')
  catdoc "${nom_file}" > "/home/$location/$(basename ${nom_file} .doc).txt"
done

since we might as well be consistently POSIX.

In general try to avoid temporary files as they'll create horrible
security issues.

Ewen




More information about the wellylug mailing list