- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to update a file content from a KShell 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
тАО09-14-2000 02:02 PM
тАО09-14-2000 02:02 PM
How to update a file content from a KShell script
How can I do that ?
--------------
Example:
(content of param.var)
LOCAL_VAR1="ABC"
LOCAL_VAR2="TOTO"
LOCAL_VAR3=25
-> Must change LOCAL_VAR2 to "TEST" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2000 02:22 PM
тАО09-14-2000 02:22 PM
Re: How to update a file content from a KShell script
Try this:
# cat master_script | sed s/LOCAL_VAR2=\"TOTO\"/LOCAL_VAR2=\"XXXX\"/g > new_script
...JRF...
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2000 02:24 PM
тАО09-14-2000 02:24 PM
Re: How to update a file content from a KShell script
Try this:
# cat master_script |sed /LOCAL_VAR2=\"TOTO\"/LOCAL_VAR2=\"XXXX\"/g > new_script
Note the backslashes to escape the quote marks in your master_script.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2000 11:35 PM
тАО09-14-2000 11:35 PM
Re: How to update a file content from a KShell script
you could also do this:
awk -F= '{
if($1 == "LOCAL_VAR2")
print $1 "=" "\"TEST\""
else
print $1 "=" $2
}' param.var >param_tmp.var
mv param_tmp.var param.var
For multiple choices add some else if (...)
statements before the else statement.
Regards
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-15-2000 06:46 AM
тАО09-15-2000 06:46 AM
Re: How to update a file content from a KShell script
IFSSAVE="$IFS"
IFS="="
while read VAR VALUE
do
if [ "$VAR" = "{variable you want to change"} ]
then
echo "$VAR={new value}" >> tmpfile
else
echo "$VAR=$VALUE" >> tmpfile
fi
done < file
mv tmpfile file
Now, the sed really makes more sense, and sed is a great thing to become familiar with, but it is sometimes easier to modify/maintain a script if you are more familiar with exactly what it does, so I figured I would give you this alternative.
But play around with sed, too. It will be worth your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-15-2000 06:49 AM
тАО09-15-2000 06:49 AM
Re: How to update a file content from a KShell script
IFSSAVE="$IFS"
IFS="="
while read VAR VALUE
do
if [ "$VAR" = "{variable you want to change"} ]
then
echo "$VAR={new value}" >> tmpfile
else
echo "$VAR=$VALUE" >> tmpfile
fi
done < file
mv tmpfile file
Now, the sed really makes more sense, and sed is a great thing to become familiar with, but it is sometimes easier to modify/maintain a script if you are more familiar with exactly what it does, so I figured I would give you this alternative.
But play around with sed, too. It will be worth your time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2000 09:38 AM
тАО09-17-2000 09:38 AM
Re: How to update a file content from a KShell script
I would use
cat param.var|sed 'LOCAL_VAR2/TEST' >newparam
I hope this helps
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2000 04:04 AM
тАО09-18-2000 04:04 AM
Re: How to update a file content from a KShell script
#!/usr/bin/ksh
# Change paramfile eg. $HOME/params
#
cat - << EOF | ed -s $HOME/params
1,$ s:LOCAL_VAR2="TOTO":LOCAL_VAR2="TEST":
w
q
EOF
Could of course be made more generic, by passing name of parameter file and which parameter to change as arguments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2000 04:57 AM
тАО09-18-2000 04:57 AM
Re: How to update a file content from a KShell script
#!/usr/bin/sh
ex param.var <
s/TOTO/TEST/
wq!
EOD
If you want to get the values for your variables into the script then you can just 'dot' the file then maybe reassign any variables that you want to override. For example:-
. param.var
LOCALVAR2=TEST
If you are trying to do anything else, please supply some more details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-18-2000 06:02 AM
тАО09-18-2000 06:02 AM
Re: How to update a file content from a KShell script
Thanks for your help.