How to pass values between awk and shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pass values between awk and shell scripts
# 8  
Old 03-20-2009
Hi

%% is used for escaping the special character %, so %%s wouldn't expect any command ant it will print the % character.

Code:
sprintf("date -d %s +%%s",d1) 

will print

date -d <value for d1> +%s

which is the command I need for converting the date in format
mm/dd/yyyy in a number (number of seconds) to be able for performing
comparations between dates (which date goes after the oter....)

For example, you can try this code

Code:
awk -v d1=03/20/2009 '
BEGIN { msg=sprintf("date -d %s +%%s",d1);
        print msg;
        system(msg);
      }'

The output will be

Code:
date -d 03/20/2009 +%s
1237503600

So, as it is expected, the probhlem is that I can't capture the value 1237503600 in awk for performing my calculations.

Thanks

Isi
# 9  
Old 03-20-2009
Read unix command into awk variable (example)

Here is an example. All code goes into your awk script ...

1. The value of the current line's $1 will be inserted into the cmd variable.
2. The string in the cmd variable will be executed in the unix shell by awk's getline, and the command's output will be saved in var (a newly created awk variable).
3. Awk will have access to the command's output via the var variable.

Code:
   cmd="echo "$1" | tr [:upper:] [:lower:]"	
   cmd | getline var
   close(cmd)
   print var

# 10  
Old 03-20-2009
Hammer & Screwdriver

กก THANKS A LOT!! :-)

It works fine, I didn't know I could execute directly the UNIX commando without system.

Thanks again for all yout help!!!

Isi
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass values to case statement in a function korn shell

I'm in the process of writng a function that consists of a case statement is there a way of calling the function and passing a value to it? ie function1 () { case opt1 do ..... opt2 do..... esac } function opt1 I'm aware the syntax is not correct, but you get the general idea. (1 Reply)
Discussion started by: squrcles
1 Replies

2. Shell Programming and Scripting

Pass values from web form to shell script

Hi, is it possible to pass more values from web form like textbox to shell script and if yes,how to do that.:confused::confused::confused: (2 Replies)
Discussion started by: tdev457
2 Replies

3. UNIX for Dummies Questions & Answers

How to pass a variable from shell to awk

I know this topic has been dealt with previously, but the solutions I've seen don't work for me apparently. I need to pass a variable defined in the shell to one in awk: $ echo $var1 3 $ cat aaa aaa 1 bbb 2 ccc 3 ddd 4 eee 5I've tried this, without success: $ awk... (2 Replies)
Discussion started by: metaltree
2 Replies

4. Shell Programming and Scripting

How to Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

5. Shell Programming and Scripting

Call java program from shell and pass values

Hi All, Can anybody please help me with how can i call my java program from shell and also pass parameter along with it so that the program can interpret the value/int and update the database. Thanks in advance Neha (1 Reply)
Discussion started by: Neha Goyal
1 Replies

6. Shell Programming and Scripting

how to pass the values to unix shell from the oracle stored procedure.

Hi i am calling a stored procedure from unix shell like this call test_proc('0002','20100218'); the stored procedure was giving output like this dbms_output.put_line(' processed earlier'); i want to see the output in the unix shell where i called. Thanks barani (6 Replies)
Discussion started by: barani75
6 Replies

7. Shell Programming and Scripting

How to pass pl/sql table values to shell script

Hello, i am using '#!/bin/bash', i want to make a loop in pl/sql, this loop takes values from a table according to some conditions, each time the loop choose 3 different variables. What i am not able to do is that during the loop i want my shell script to read this 3 variables and run a shell... (1 Reply)
Discussion started by: rosalinda
1 Replies

8. Shell Programming and Scripting

need help on shell script(to pass the values)

only the arguments that are written to the file, my script is (sh /u01app/wkf.sh"$start_no","$name","$Condition","$file_name") like that when ever I run my script I need to write into a new file every time, like wise I have upto10 files with different names.bec my $start_no and $name will... (1 Reply)
Discussion started by: sai123
1 Replies

9. UNIX for Dummies Questions & Answers

How to pass values from one file to different scripts

Hi Gurus, Iam new to Unix. I had a requirement where i should use a file for example Host.sh or Host.txt Host = 555.254.45.14 username = aaaa pwd = SSSSSS123 And this file need to be used in different scripts. For example i have script1.sh where i want to use the values of... (6 Replies)
Discussion started by: pssandeep
6 Replies

10. UNIX for Dummies Questions & Answers

how to pass values from oracle sql plus to unix shell script

how to pass values from oracle sql plus to unix shell script (2 Replies)
Discussion started by: trichyselva
2 Replies
Login or Register to Ask a Question