- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- question on vi
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
03-02-2005 03:25 PM
03-02-2005 03:25 PM
I need to make a script in which I must substitute some symbols, after "if else" construction.
For example I need to change all "a" symbols to "b".
Is it possible to make it using vi, so then I can start my script from command line?
#./myscript
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2005 03:31 PM
03-02-2005 03:31 PM
SolutionSorry, I'm a little unclear on the question. Are you trying to run "myscript", which opens another file "myfile" and changes all "a" to "b"?
In vi:
:1,$s/a/b/g
In sed:
sed "s/a/b/g"
Perl is a nice language for string manipulation -- better IMO than shells or vi.
HTH,
Mic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2005 03:45 PM
03-02-2005 03:45 PM
Re: question on vi
thank you!
And how to do the same thing in one file?
Here is the example of myscript:
#!/usr/bin/sh
HM=$(hostname)
then I have some commands operating with hostnames, and I need to change hostnames to $HM.
To do that I have to press ":" in command mode and then type what you said. But I need to that automaticly by running myscript.
Is it possible?
I think that only sed is able to do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2005 04:15 PM
03-02-2005 04:15 PM
Re: question on vi
> To do that I have to press ":" in command
> mode and then type what you said. But I need
> to that automaticly by running myscript.
> Is it possible?
> I think that only sed is able to do it.
Yes, you need to use sed. Use following command
in your script:
cat old_file | sed "s/old_hostname/$HN/g" > new_file
The old_file is the name of the file with old
hostname and new_file is exactly same as old file
with hostname changed to whatever string $HN set
to.
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2005 05:31 PM
03-02-2005 05:31 PM
Re: question on vi
HTH
tienna