system () output into file in awk

hello,

I want to print my output into a file inside of awk, but I don't know it could wokr with using system (piping the $1-4 to another shellskript):

cat file.txt |awk '{ if ($5==2) {dataname=$1 "_" $2 "_" $3 "_" $4 "_typing.rad"
befehl=".gen_test " $7 " " $8 " " $8
system(befehl) > dataname}}'

Does anyone has an idea?

Thanks a lot,
Sandra

Hi.

Something like this?:

cat file.txt | awk '{
   if ($5==2) {
     dataname=$1 "_" $2 "_" $3 "_" $4 "_typing.rad"
     befehl=".gen_test " $7 " " $8 " " $8
     system(befehl ">" dataname)
   }
}
 

The use of cat is redundant:

awk '
$5==2{
  dataname=$1 "_" $2 "_" $3 "_" $4 "_typing.rad"
  befehl=".gen_test " $7 " " $8 " " $8
  system(befehl " >" dataname)
}' file.txt

thanks a lot. This works perfectly.

Last question in this case. In Shell the radiance-command work like that:

gensurf seitenwand rollerblind1 '-0.95*s' '0.046' '2.85-'$1'*t' 1 1

But I don't know how to deal with this command in system().

I tried this:

befehl1="gensurf seitenwand rollerblind1 '-0.95*s' '0.046' '2.85-"$1"*t' 1 1 >temp.rad"

But it is just printing exactly the command with the replaced $1. How can I solve the '. Can someone tell me maybe the rules?

Thanks again for the help,
Sandra

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

I have still the problem with the translation of the following command in awk. In Shell the radiance-command work like that:

gensurf seitenwand rollerblind1 '-0.95*s' '0.046' '2.85-'$1'*t' 1 1

gensurf seitenwand rollerblind1 '-0.95*s' '0.046' '2.85-'$1'*t' 1 1

But I don't know how to deal with this command in system(). My skript looks like this. the importfile runde.txt is just a tabel with seven columns and numbers in it. I wanted to create a surface with different parameters getting out of the runde.txt file and written in the next course file *_adjust.rad:

cat runde.txt |awk '{

                                if ($5==2) {
                                                   dataname_v= " $1 "_" $4 "_adjust.rad
                                                   befehl1="gensurf seitenwand rollerblind1 '-0.95*s' '0.046' '2.85-"$7"*t' 1 1 > dataname_v"
                                                   system(befehl)
                                          }
                    }'

cat runde.txt |awk '{ if ($5==2) { dataname_v= " $1 "_" $4 "_adjust.rad befehl1="gensurf seitenwand rollerblind1 '-0.95*s' '0.046' '2.85-"$7"*t' 1 1 > dataname_v" system(befehl) } }'

The problem is the '-sign, because in awk it is used for '{ and always when I am changing it the befehl-variable it is just printing the command with a replaced $7. Or it is telling me that the gensurf-command is used wrong because it is missing the end of the command...

Does anyone has an idea how to solve it? Maybe connecting strings?

Thanks a lot,
Ergy