- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed with read input
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
тАО07-23-2009 06:09 AM
тАО07-23-2009 06:09 AM
sed with read input
The sed command doesn't work.. Do you know what is the correct syntax of sed command?
I want to change the IP-address of the APN.
Many thanks.
John
#!/bin/sh
printf "Which APN you want to migrate? "
read APN
printf "\n\n"
printf "You want to migrate this APN: $APN"
printf "\n\n"
printf "Current IP of this APN: $APN"
printf "\n\n"
cat gprs.zone | grep "$APN"
printf "\n\n"
printf "\n\n"
sed '/$APN/s/10.10.10.12/10.10.10.225/g' gprs.zone > gprs.zone.new
sed '/$APN/s/10.10.10.40/10.10.10.229/g' gprs.zone > gprs.zone.new
printf "result"
printf "\n\n"
cat gprs.zone.new | grep "$APN"
exit
Printout of the shell script.
***********************************************
Which APN you want to migrate? test.com
You want to migrate this APN: test.com
Current IP of this APN: test.com
test.com IN A 10.10.10.40
test.com IN A 10.10.10.12
result
test.com IN A 10.10.10.40
test.com IN A 10.10.10.12
***********************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 06:15 AM
тАО07-23-2009 06:15 AM
Re: sed with read input
Sed examples.
$commandline = "sed s/juf.org/juf.net/g ${filetoback} > $filetoback.bck";
system("${commandline}");
$commandline = "cp ${filetoback}.bck ${filetoback}";
system("${commandline}");
This is pulled from a perl script that goes to the command shell to do some sed conversion.
Pretend the perl part isn't around.
the cp command copies the output of the sed command over the original data file.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 06:17 AM
тАО07-23-2009 06:17 AM
Re: sed with read input
cat gprs.zone | sed '/$APN/s/10.10.10.12/10.10.10.225/g' > gprs.zone.new
yet ?
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 06:38 AM
тАО07-23-2009 06:38 AM
Re: sed with read input
Using:
# sed '/$APN/s/10.10.10.40/10.10.10.229/g'
...with the single quotes is not going to allow interpolation of your APN variable. Instead use:
# sed "/$APN/s/10.10.10.40/10.10.10.229/g"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 07:05 AM
тАО07-23-2009 07:05 AM
Re: sed with read input
printf "Which APN you want to migrate? "
read APN
printf "\n\n"
printf "You want to migrate this APN: $APN"
printf "\n\n"
printf "Current IP of this APN: $APN"
printf "\n\n"
cat gprs.zone | grep "$APN"
printf "\n\n"
printf "\n\n"
sed "/$APN/s/10.10.10.12/10.10.10.225/g" gprs.zone > gprs.zone.new
sed "/$APN/s/10.10.10.40/10.10.10.229/g" gprs.zone > gprs.zone.new
printf "result"
printf "\n\n"
cat gprs.zone.new | grep "$APN"
exit
Result of the script:
Which APN you want to migrate? test.com
You want to migrate this APN: test.com
Current IP of this APN: test.com
test.com IN A 10.10.10.40
test.com IN A 10.10.10.12
result
test.com IN A 10.10.10.229
test.com IN A 10.10.10.12
It is better now but still not 100%.
Problem now is: the second IP-address is not changed... do I need to do for or while loop?
Best regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 07:16 AM
тАО07-23-2009 07:16 AM
Re: sed with read input
> Problem now is: the second IP-address is not changed... do I need to do for or while loop?
Yes, you overwrote your output when you did the second substitution!
# sed -e "/$APN/s/10.10.10.12/10.10.10.225/g" -e "/$APN/s/10.10.10.40/10.10.10.229/g" gprs.zone > gprs.zone.new
...will fix your problem.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2009 07:34 AM
тАО07-23-2009 07:34 AM
Re: sed with read input
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2009 01:56 AM
тАО07-24-2009 01:56 AM
Re: sed with read input
To be pedantic, you should quote each ".":
sed /$APN/s/'10\.10\.10\.12/10.10.10.225/g'
>Tingli: The funny thing is that sed won't work for the last line in a file, as the last line doesn't have a newline in its end.
That's way it is suppose to work. sed only works on text files and lines must be terminated by a newline.
http://docs.hp.com/en/B2355-60130/glossary.9.html#d0e1257203