- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk help to process a resource file by a shell scr...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 06:45 AM
тАО05-24-2005 06:45 AM
I have a general resource file of the following format that must be read and sourced by several shell scripts:
Loading.NRT_DAYS=1
Loading.POLLING_INTERVAL=5
#Loading.POLLING_INTERVAL=30
Loading.MASK=*
Running.NRT_DAYS=1
Running.POLLING_INTERVAL=5
#Running.POLLING_INTERVAL=30
тАж
Where:
Line beginning with #, are comments
Each entry has the format: Script_name.variable_name=value
I want to write within my shell script an awk command to read and parse this file. For each line matching the script name, it will:
export variable_name=value
тАж
I am quiet proficient in shell scripting and tha kind of parsing is complex because * can be a valueтАж
I believe the parsing can be achieved by a simple awk commandтАж
Any help/suggestion is highly appreciated.
Thanks in advance for your help,
Kind Regards,
Rui
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 07:23 AM
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 07:30 AM
тАО05-24-2005 07:30 AM
Re: Awk help to process a resource file by a shell script
create a seperate file for loading, running, etc.; put the files all in the same directory
and instead of lines like:
Running.NRT_DAYS=1
make them like this:
export NRT_DAYS=1
then exporting the variables is as easy as:
. $dirWhereFilesAre/$yourScriptName
just a suggestion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 07:41 AM
тАО05-24-2005 07:41 AM
Re: Awk help to process a resource file by a shell script
no gurus around here...
But the attached script may serve as a starting point. Try it with your input file as $1.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 08:20 AM
тАО05-24-2005 08:20 AM
Re: Awk help to process a resource file by a shell script
Some of the other guys suggest sourcing in your resource file(s) directly, which will work fine, assuming you have the capability to make this change (it's a manually generated file, and not generated by some closed-source app).
However, this mechanism assumes a level of trust that noone has put malware-type commands into the resource file(s), as they would be happily executed with the permissions of the user running the script. Of course, if the write permissions on the resource file(s) are as restrictive or stronger than execute permissions on the script, then this isn't a big deal.
Just something to think about...
--Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-24-2005 11:49 AM
тАО05-24-2005 11:49 AM
Re: Awk help to process a resource file by a shell script
Which shell are you going to use?
Generally you could use something like Rodney's solution (expanding upon that a little) in `` shell-execution, but some shells might not allow it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 01:26 AM
тАО05-31-2005 01:26 AM
Re: Awk help to process a resource file by a shell script
!/usr/bin/awk
FILENAME=$1
awk -F'.' `
BEGIN { script_name=$FILENAME }
{ if($1==script_name) 'print "export "$2' }
`
$ myscript <script name>
I am not sure if the awk uses forward quotes or single quotes for instruction. You might try it. Sorry, I haven't tested this program. But am sure it will help you in writing one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 05:55 PM
тАО05-31-2005 05:55 PM
Re: Awk help to process a resource file by a shell script
$ cat myscript
FILENAME=$1
awk -v script_name=$FILENAME -F "." '
{ if($1==script_name) print "export " $2 }
'< resource_file
Output:
========
$ ./myscript Loading
export NRT_DAYS=1
export POLLING_INTERVAL=5
export MASK=*
$ ./myscript Running
export NRT_DAYS=1
export POLLING_INTERVAL=5
I hope this helps.
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-31-2005 09:41 PM
тАО05-31-2005 09:41 PM
Re: Awk help to process a resource file by a shell script
resource.log
Loading.NRT_DAYS=1
Loading.POLLING_INTERVAL=5
#Loading.POLLING_INTERVAL=30
Loading.MASK=*
Running.NRT_DAYS=1
Running.POLLING_INTERVAL=5
#Running.POLLING_INTERVAL=30
Then, You can try in each script file as,
---- Loading file ---
File=$(basename $0 | cut -d"." -f1)
for var in `grep $FILE resource.log | cut -d"." -f2-`
do
variable=$(echo $var | cut -d"=" -f1)
value=$(echo $var | cut -d"=" -f2)
export $variable=$value
done
Keep the same in all required files.
hth.