- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell scripting
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
Forums
Discussions
Discussions
Discussions
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
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-18-2001 10:21 AM
09-18-2001 10:21 AM
DefPath=/home/mcltech/NetS24V3/subnet4/files
QuePath=/home/mcltech/NetS24V3/subnet4/queues
LogPath=/home/mcltech/NetS24V3/subnet4/log
BinPath=/home/mcltech/NetS24V3/bin
I need to replace subnet4 with a new subnet number that will be set in a variable earlier in the script.
My problem is, with using sed the changes are made and sent to standard output and when I try to use the w at the end of the substitution string it overwrites the complete file. Can anyone tell me how to make this change without overwriting the entire file?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2001 10:44 AM
09-18-2001 10:44 AM
SolutionOne of the ways you can do is
DefPath=/home/mcltech/NetS24V3/subnet4/files
DefPath=$(echo $DefPath | sed 's/subnet4/'$variable_defined_earlier'/')
Now, subnet4 in DefPath will be updated by the new variable you assigned early on in the script
Does this help?
-Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2001 10:45 AM
09-18-2001 10:45 AM
Re: shell scripting
TDIR=${TMPDIR:-/var/tmp}
PID=${$}
T1=${TDIR}/X${PID}_1.tmp
for FILE in ${FILELIST}
do
sed -e myscript ${FILE} > ${T1}
STAT=$?
if [ ${STAT} -eq 0 ]
then
mv ${T1} ${FILE}
else
echo "Sed failed for file ${FILE}; status ${STAT}." >&2
fi
done
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2001 10:53 AM
09-18-2001 10:53 AM
Re: shell scripting
I misread your question, if you are modifying the file after you copy it through your script then you will have to use a tempfile and then move it like clay suggested.
Unfortunately that's how sed works and we can't do anything about it
-Regards
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2001 11:26 AM
09-18-2001 11:26 AM
Re: shell scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2001 04:07 PM
09-18-2001 04:07 PM
Re: shell scripting
ex -s -c "s/from/to/g|wq" yourFile
ex - yourFile <<-EOFILE
s/from/to/g
wq
EOFILE
you could do a seach on ex to find other examples