LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-27-2014, 04:42 AM   #1
ripudaman.singh
LQ Newbie
 
Registered: Aug 2014
Posts: 1

Rep: Reputation: Disabled
Passing Multiple shell variables to awk script doesn't work


echo $jdbc_url
echo $v_Password
echo $jdbc_url

awk -F"=" -v awk_v_SchemaName=$v_SchemaName -v awk_v_Password=$v_Password -v awk_jdbc_url=$jdbc_url '{
if ( $1 == "jdbc.url" ) {
print awk_jdbc_url
}
else if ( $1 == "jdbc.username" ) {
print awk_v_SchemaName
}
else if ( $1 == "jdbc.password" ) {
print awk_v_Password
}
else {
print $0
}
}' file_name >> file_name_modified

why does it print blank for awk_v_SchemaName, awk_v_Password? though echo statements on top of awk command prints assigned values

Any alternative do I have? This is hell irritating with awk, something work, something doesn't... lot many times I waste time on it and finally apt other approaches

Please help me if possible

Last edited by ripudaman.singh; 08-27-2014 at 04:43 AM.
 
Old 08-27-2014, 05:03 AM   #2
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
there is an ENVIRON special variable available in awk:
Code:
$ awk 'BEGIN{print ENVIRON["USER"]}' < /dev/null
ygrex
$ env USER=fake-user-name awk 'BEGIN{print ENVIRON["USER"]}' < /dev/null
fake-user-name
should be suitable for your use-case
 
Old 08-27-2014, 05:12 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
If you used [code] and [/code] tags, we could read your program.

PS: here as an example:
Code:
awk -v var1='first val' \
    -v var2='second val' \
    'BEGIN { print var1; print var2; }' </dev/null

Last edited by NevemTeve; 08-27-2014 at 06:10 AM.
 
Old 08-27-2014, 07:30 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
What version of awk?

What derivation of awk? (ie gawk, nawk, mawk??)

Although it should be obvious from the awk script, may we have some examples of what the file contents look like? (obviously change any sensitive information values)

And as above, please use code tags.

As far as awk_v_SchemaName goes, according to your bash echoes, this variable is set to nothing as there was no bash variable called v_SchemaName
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script - displaying multiple variables mobarger Linux - General 6 10-19-2016 08:56 PM
[SOLVED] Passing multiple arguments in shell script dgs012 Linux - Newbie 7 12-11-2010 12:06 PM
Passing Environment variables to a shell-script kregec05 Programming 6 08-18-2009 08:27 AM
passing awk output to $variable for shell script? NewnanNOC Programming 3 10-23-2008 02:08 PM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration