LinuxQuestions.org
Help answer threads with 0 replies.
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 03-08-2007, 01:14 AM   #1
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Rep: Reputation: 15
what does this awk script do?


Hi,

I would like to know what this awk script does?

filename: bt.as
Code:
BEGIN   {
                "echo $ORA_DB" | getline oracle_home;
                "echo $ORA_APP" | getline oracle_home;
                "echo $ORA_BASE" | getline oracle_base;
        }
/\$ORA_DB/ {gsub("\$ORA_DB",oracle_home);}
/\$ORA_BASE/ {gsub("\$ORA_BASE",oracle_base);}
{print $0 }
this is invoked as:

Code:
awk -f bt.as $PRODUCT_DIR/osmf-http._env > $PRODUCT_DIR/osmf-http.env.bt
 
Old 03-08-2007, 07:16 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The script will probably not do that much, both gsub statements are incorrect.
It should be: gsub(/string/,replacement), not gsub("string",replacement).

What the maker probably tried to do is:

Get the content of environment variables called ORA_DB, ORA_APP, ORA_BASE and stores these in oracle_home and oracle_base (Strange: both ORA_DB and ORA_APP are stored in oracle_home, the second overriding the first, which is _probably_ incorrect/unwanted).

After this is done, all lines in $PRODUCT_DIR/osmf-http._env are checked for the existence of \$ORA_DB and/or \$ORA_BASE (the literal name, not the content) and substitute these with the content found in the environment variable.

I.e:
If ORA_DB holds /path/to/db, oracle_home is set to /path/to/db
If $PRODUCT_DIR/osmf-http._env has the following line: $ORA_DB/http/specific/db it will be changed to:
/path/to/db/http/specific/db

But like I stated before: The script isn't written correctly and will probably not work.

Hope this clears things up a bit.
 
Old 03-08-2007, 02:32 PM   #3
cfaj
Member
 
Registered: Dec 2003
Location: Toronto, Canada
Distribution: Mint, Mandriva
Posts: 221

Rep: Reputation: 31
Quote:
Originally Posted by druuna
Hi,

The script will probably not do that much, both gsub statements are incorrect.
It should be: gsub(/string/,replacement), not gsub("string",replacement).
More accurately, it is gsub(/regexp/,replacement), and there is nothing wrong with gsub("string",replacement):

Code:
$ echo qwertyuiopqwertyuiop | awk '{gsub( "rty","ZXC" ); print }'
qweZXCuiopqweZXCuiop
 
Old 03-08-2007, 03:10 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Gnu awk is forgiving and using "..." instead of /.../ will probably have the same results. But...

Other awk flavors (awk/mawk/nawk to name just 3) are stricter/different and only work when using the correct syntax (as found in many awk documents/books).

It's always good practise to use syntactically correct commands, these will work in all flavors. All other extra 'stuff' is great, but will probably bind you to one specific flavor.

gsub(/regexp/,replacement) => works on gnu awk/awk/nawk (don't have mawk around, but it will probably work) and is in general syntactically correct.

gsub("string",replacement) => will work with gnu awk and (BSD)awk, will not work with nawk and (SUN) awk.
 
  


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
need help fixing and optimizing AWK script hedpe Programming 5 08-29-2006 08:30 AM
writing awk script files bigmark Linux - Software 1 10-19-2005 10:33 AM
About awk script sachin_keluskar Linux - Software 2 06-24-2005 03:19 AM
Passing variables from AWK script to my shell script BigLarry Programming 1 06-12-2004 04:32 AM
How do I run an awk script? davee Programming 2 08-12-2003 08:46 AM

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

All times are GMT -5. The time now is 12:52 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