Passing values out awk.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing values out awk.
# 1  
Old 11-28-2003
Question Passing values out awk.

found that passing (input) values to awk, all work well. For example:
errpt | awk 'BEGIN { errore=0 }
substr($2,1,4) /'ParamData'/ {
....
} ' ParamData=`date +"%m%d"`

Now I wish to obtain (output) a value. Using this method is it possible to re-write ParamData, for example?

Thanks in advance for your kind cooperation.
Regards.

Giovanni
# 2  
Old 11-28-2003
You can print the value in awk and read it into your script, e.g...

$ echo 1 | awk '{print $1 + p}' p=2 | read p
$ echo $p
3
# 3  
Old 12-09-2003
Ygor,
Over the past week or so I have had to write a couple of awk scripts and have really begun to see how powerful it can be. However, awk is still a bit foreign to me, can you elaborate on this syntax for me? What confuses me is the fact that p=2 is outside of the ending quote for the awk peice. How is the value of 2 available to awk?

echo 1 | awk '{print $1 + p}' p=2 | read p
# 4  
Old 12-09-2003
Ygor really a expert in awk!! I viewed his posts and I still need to learn from him/her.

I know that is one of method to set variable in awk.

And I know 3 methods to do that, maybe more than 3 ways then I may not know.
Method 1:
Variable was assigned after any actions, var cannot be read in BEGIN {} because action in BEGIN {} is started before reading the script.
awk '{print $0}' var=$1 filename

Method 2:
One variable with one -v, variable can be read in BEGIN{} and the script.
awk -v var1=$1 -v var2=$2 '{print $0}' filename

Method 3:
assign variable in the script body.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Values passing out of isql session

hi .. i have a isql session which inside which i have two variables defined.. i wanna calculate % based on those variables. i knw i can easily do % calculation in csh if i could get the value of these variables passed outside the isql session . is tat possible ?? pls advice somthin like below... (1 Reply)
Discussion started by: Rahul619
1 Replies

2. Shell Programming and Scripting

Passing values from awk to shell variable

I am writing a script where I need awk to test if two columns are the same and shell to do something if they are or are not. Here is the code I'm working with: @ test = 0 ... test = `awk '{if($1!=$2) print 1; else print 0}' time_test.tmp` #time_test.tmp holds two values separated by a space... (3 Replies)
Discussion started by: Malavin
3 Replies

3. Shell Programming and Scripting

passing values to the shell script

Hi, Solaris : 10 . I have 3 database in single file system i.e. /d01 . whenever I connect to oracle user using the below method #su - oracle It will prompt for which database environment you want to set(PROD,TEST,UAT) : whichever i need i will enter required DATABASE and perform my... (2 Replies)
Discussion started by: maooah
2 Replies

4. Shell Programming and Scripting

Passing Values to remote server

I'm trying to pass there values from the present server to the remote server. here is the below code. function abc() { export a=$1 export b=$2 export c="$3" export d="$4" #servers Servers=$(echo server40{1..3}p.s.com) for host in ${Servers}; do #server login ssh $host... (4 Replies)
Discussion started by: Amutha
4 Replies

5. Programming

Passing multiple values from a function in C

I know multiple values can be returned from a function in C like this: char **read_file ( char * , unsigned long int * );//this is the function prototypeunsigned long int number_of_words = 0;//variable defined in main() and initialized to 0words_from_dictionary = read_file ( "dictionary.dit" ,... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

6. Web Development

Help with passing HTML values in to JavaScript

Not sure if this is the right place to ask this but here goes. I am creating a cheat sheet for co-workers. The concept is that you pick wire size and conduit size and the amount of wires that will fit is displayed. I haven't used alot of drop downs and can't quite figure out the way the get id... (3 Replies)
Discussion started by: zero3ree
3 Replies

7. Shell Programming and Scripting

passing values to function in Ksh

Hi, I'm trying to work on the script given below #!/bin/ksh -x pfile() { echo "$1" } touch smp19 echo "Hi" > smp19 result=$(pfile $smp19) echo $result As highlighted , when i pass $smp19 as parameter ,it does not display the output.However when i try giving "Hi" instead... (2 Replies)
Discussion started by: Sheema
2 Replies

8. Shell Programming and Scripting

passing values into logrotate??

Wondering if this is possible? OK, here is my question. I'm backing up a TON of different logs in different locations. I'm querying a database for the information. What I'd like to do, is pass that information into a logrotate script for the backup.. i.e. I'm trying to do the following: ... (1 Reply)
Discussion started by: imbiea
1 Replies

9. Shell Programming and Scripting

passing variable values to awk command

Hi, I have a situation where I have to specify a different value to an awk command, I beleive i have the gist of this done, however I am not able to get this correct. Here is what I have so far echo $id 065859555 This value occurs in a "pipe" delimited file in postition 8. Hence I would... (1 Reply)
Discussion started by: jerardfjay
1 Replies

10. UNIX for Advanced & Expert Users

Passing values from SQR to UNIX

UNIX script running a SQR program.... no problem passing values to SQR program... trying to pass values back to UNIX.... I'm currently creating a file from the SQR program and then using the Unix READ command to read the file and retrieve the value.... Is there an easier way to pass the... (2 Replies)
Discussion started by: seeuinoz
2 Replies
Login or Register to Ask a Question