Visit Our UNIX and Linux User Community


system () output into file in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting system () output into file in awk
# 1  
Old 09-07-2009
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):

Code:
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

Last edited by Franklin52; 09-07-2009 at 09:50 AM.. Reason: Please use code tags!
# 2  
Old 09-07-2009
Hi.

Something like this?:

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

# 3  
Old 09-07-2009
The use of cat is redundant:

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

# 4  
Old 09-07-2009
thanks a lot. This works perfectly.

Last question in this case. In Shell the radiance-command work like that:
Code:
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:
Code:
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

Last edited by vbe; 09-07-2009 at 12:01 PM.. Reason: code tags...
# 5  
Old 09-07-2009
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 [code] and [/code] 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
# 6  
Old 09-17-2009
connecting strings?

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

Code:
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:

Code:
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

Previous Thread | Next Thread
Test Your Knowledge in Computers #599
Difficulty: Medium
For modern C programming, defining functions is a two step process. First, you declare a function and its signature using a prototype. Then you define the function by providing a function body that defines what the function does.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. UNIX for Dummies Questions & Answers

awk - Rename output file, after processing, same as input file

I have one input file ABC.txt and one output DEF.txt. After the ABC is processed and created output, I want to rename ABC.txt to ABC.orig and DEF to ABC.txt. Currently when I am doing this, it does not process the input file as it cannot read and write to the same file. How can I achieve this? ... (12 Replies)
Discussion started by: High-T
12 Replies

3. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

AWK Script to convert input file(s) to output file

Hi All, I am hoping someone can help me with some scripting I need to complete using AWK. I'm trying to process multiple fixed files to generate one concatenated fixed file in a standard format. The Input file is:- aaaa bbbbb ccccc 1 xxxx aaa bbb aaaa bbbbb ccccc 2 abcd aaa CCC... (9 Replies)
Discussion started by: jason_v_brown
9 Replies

6. Shell Programming and Scripting

Capturing awk's system(cmd) output

Hi everybody, I am working on a bigger awk script in which one part is comparing the size of two files. I want to evaluate which file is bigger and then just save the bigger one. I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently... (2 Replies)
Discussion started by: iMeal
2 Replies

7. Shell Programming and Scripting

awk - Pre-populating an array from system command output

So, here's a scenario that requires the same logic as what I'm working on: Suppose that you have a directory containing files named after users. For awk's purposes, the filename is a single field-- something parse-friendly, like john_smith. Now, let's say that I'd like to populate an array in... (2 Replies)
Discussion started by: treesloth
2 Replies

8. Shell Programming and Scripting

Parse file using awk and work in awk output

hi guys, i want to parse a file using public function, the file contain raw data in the below format i want to get the output like this to load it to Oracle DB MARWA1,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 MARWA2,BSS:26,1,3,0,0,0,0,0.00,22,22,22.00 this the file raw format: Number of... (6 Replies)
Discussion started by: dagigg
6 Replies

9. Shell Programming and Scripting

AWK Output to file.

I have this awk instructions: #Interface with description awk '/hostname/{a=$0} /interface/{b=$0} /address/{print a b $0}' informe-router.txt awk '/interface/{b=$0} /address/{c=$0} /description/{print b c $0}' informe-router.txt awk '/router/,/network/{print $0}' informe-router.txt and I... (2 Replies)
Discussion started by: bobbasystem
2 Replies

10. Shell Programming and Scripting

Can df output be forced to a single line for each file system?

df generates the following output on one of our systems: df -k Filesystem 1K-blocks Used Available Use% Mounted on /dev/vx/dsk/rootvol 4131866 3593316 497232 88% / swap 19963152 144 19963008 1% /var/run swap 19985184 ... (6 Replies)
Discussion started by: shew01
6 Replies

Featured Tech Videos