how to pass variables surrounded in double quotes to awk?


 
Thread Tools Search this Thread
Operating Systems AIX how to pass variables surrounded in double quotes to awk?
# 1  
Old 03-24-2006
how to pass variables surrounded in double quotes to awk?

Hi,
I'm making progress on this but hung up on one last detail. I'd like to use AWK to pass the system date and time(among other things) to the first line of a file.

Here's what I have:

BEGIN {TOTALPP = 0;FREEPP=0;USEDPP=0;print "LPAR NAME:",lpar,"DATE:",tdate }

I call AWK with the following:
./diskchartstart_results | awk -v lpar=$NODE tdate=`date` -f testawk4 | more

My results:
awk: Cannot find or open file Mar.

The source line number is 1.
./diskchartstart_results: Broken pipe

Where our date format is:

Fri Mar 24 12:54:02 CST 2006

I then tried to pass tdate to awk as a variable itself:
./diskchartstart_results | awk -v lpar=$NODE tdate=$tdat -f testawk4 | more

Where tdat=`date`, then exported it.

My results:
syntax error The source line is 1.
The error context is
>>> tdate="Fri <<<
awk: Quitting
The source line is 1.
./diskchartstart_results: Broken pipe

So, then I figured I needed to pass tdat with double quotes around it:
tdat=\"`date`\"
root@test:/home/ash934 > echo $tdat
"Fri Mar 24 13:42:11 CST 2006"

but I end up with the same error from AWK. I have the feeling I'm missing something pretty simple. Any ideas on a clean way to get that done?
# 2  
Old 03-24-2006
I beieve that your syntax problem is that, for each variable passed to awk, you need to provide "-v"

Try this:

Code:
./diskchartstart_results | awk -v lpar=$NODE -v tdate=`date` -f testawk4 | more

# 3  
Old 03-24-2006
I tried your sugestion and oddly enough, it returns the same error except now it chokes on 24

Fri Mar 24 12:54:02 CST 2006

results:
awk: Cannot find or open file 24.

The source line number is 1.
./diskchartstart_results: Broken pipe

Any other ideas?
# 4  
Old 03-24-2006
I tried it as follows and it works for me:

Code:
print "aaaaa" | nawk -v lpar=$(hostname) -v tdate="`date`" -f testawk4.awk

I added double quotes around the date and I used nawk because my awk doesn't permit variables.
# 5  
Old 03-24-2006
YES! This works!!! I tired so many combinations, I forgot to go back and use double quotes after your sugestion of using -v for each parameter.

Thank you, have a GOOD Weekend, tmarikle!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk -File contain double quotes

Hi ALL, file data like : test.csv a,b,"c,d" my awk version is 4.0.2 ,if i am using the below code is working fine. awk -vFPAT='(*)|("+")' -vOFS="," '{print $3}' test.csv if the awk version is 3.1.7 is not working . Could you please help me on this one. output should be : "c,d" (6 Replies)
Discussion started by: bmk123
6 Replies

2. Shell Programming and Scripting

Replace Double quotes within double quotes in a column with space while loading a CSV file

Hi All, I'm unable to load the data using sql loader where there are double quotes within the double quotes As these are optionally enclosed by double quotes. Sample Data : "221100",138.00,"D","0019/1477","44012075","49938","49938/15043000","Television - 22" Refurbished - Airwave","Supply... (6 Replies)
Discussion started by: mlavanya
6 Replies

3. Shell Programming and Scripting

How to match fields surrounded by double quotes with commas?

Hello to all, I'm trying to match only fields surrounded by double quotes that have one or more commas inside. The text is like this "one, t2o",334,"tst,982-0",881,"kmk 9-l","kkd, 115-001, jj-3",5 The matches should be "one, t2o" "tst,982-0" "kkd, 115-001, jj-3" I'm trying with... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

4. Shell Programming and Scripting

How to pass two words within double quotes as variable?

Hi All, OS - Suse 10 ksh --version version sh (AT&T Research) 93s+ 2008-01-31 I am passing two words within double quotes ("Application Developer") to script as variable, but script is adding two single quotes between two words like ("Application' 'Developer"). below is simple test... (4 Replies)
Discussion started by: srimitta
4 Replies

5. UNIX for Dummies Questions & Answers

Help populating double quotes using awk

Want to populate double quotes for each filed using awk: Input: cat file.txt => "1-23-test_test1-test2" Required output : "1-23-test_test1-test2"|"#GT_properties_xyz" Was trying the below command on solaris 9 machine : awk -F"|" '{print $1"|""#GT_properties_xyz"}' file.txt ... (8 Replies)
Discussion started by: rajachandhok
8 Replies

6. Shell Programming and Scripting

Replace double double quotes using AWK/SED

Hi, I have data as "01/22/97-"aaaaaaaaaaaaaaaaa""aaa""aabbbbbbbbcccccc""zbcd""dddddddddeeeeeeeeefffffff" I want to remove only the Consequitive double quotes and not the one which occurs single. My O/P must be ... (2 Replies)
Discussion started by: Bhuvaneswari
2 Replies

7. Shell Programming and Scripting

Using double quotes in awk

Hi I read somewhere that when using double quotes in awk; variables gets expanded else it doesn't. So I tried to use the double quotes inside an awk statement as below: from_instance_trans=`awk "/INPUT =\"$frm_inst\"/,/<\/TRANSFORMATION>/" $xml_object | grep -w "<TRANSFIELD" | awk... (9 Replies)
Discussion started by: dips_ag
9 Replies

8. Shell Programming and Scripting

awk - double quotes as record separator

How do I use double quotes as a record seperator in awk? (4 Replies)
Discussion started by: locoroco
4 Replies

9. Shell Programming and Scripting

How to pass a parameter with double quotes around it to a command

In a bash script, I need to pass a parameter that has space in-between using double quotes as follows: CMD="SomeExecutable" # Parameter that has a space in-between PARAM1="TIMO 2" CMD_IN="--name=\"$PARAM1\"" CMD_OUT=`$CMD $CMD_IN` expected/required command execution:... (4 Replies)
Discussion started by: Timo
4 Replies

10. Shell Programming and Scripting

Use variables with double quotes sed -i

I have the following line of code: sed -i "/MatchText/ s/${tgrepLine}/${tNewLine}/" filename.outputfilename.output contains this: blablabla PATH=".:/home/root/bin/:/usr/local/bin/" blablablaVariable ${tgrepLine} contains: PATH=".:/home/root/bin/:/usr/local/bin/" Variable ${tNewLine}... (3 Replies)
Discussion started by: inspire87
3 Replies
Login or Register to Ask a Question