- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Search and replace Text in a File
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
10-19-2008 04:42 AM
10-19-2008 04:42 AM
I want a replace a text
like "/asia/Calcutta" to "/india" in a
file using some unix commands . Any
suggestions would be helpful .
--Rob
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2008 05:07 AM
10-19-2008 05:07 AM
Re: Search and replace Text in a File
A Forum search for "sed" should find many
examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2008 05:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2008 04:01 PM
10-19-2008 04:01 PM
Re: Search and replace Text in a File
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 12:57 AM
10-20-2008 12:57 AM
Re: Search and replace Text in a File
having to quote directory slashes
sed 's!/asia/Calcutta/!/India/g'
also you can put the various sed commands
in a seperate text file
's!/asia/Calcutta/!/India/g'
's!/asia/Bomnay/!/India/g'
's!/asia/Delhi/!/India/g'
sed -f script_file
-f script_file Take script from file script_file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 01:33 AM
10-20-2008 01:33 AM
Re: Search and replace Text in a File
vi file name
in cmd mode
If you want to replace asia only
:%s/asia/india/g
In case you want to replace /asia/Calcutta with /india then use
:%s/asia\/Calcutta/india/g
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 05:06 AM
10-20-2008 05:06 AM
Re: Search and replace Text in a File
All the suggestion posted by you doesnt help . For everything I am getting line cannot be parsed message .
if there is any other way please help me out .
--Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 05:28 AM
10-20-2008 05:28 AM
Re: Search and replace Text in a File
> help .
You're not helping us much, either.
> For everything I am getting line cannot be
> parsed message .
"Everything" covers a big region. Perhaps if
we were psychic, or if you showed your actual
commands with their actual results, we might
be able to guess what you did wrong.
"Doesn't work" is not a useful problem
description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 05:53 AM
10-20-2008 05:53 AM
Re: Search and replace Text in a File
Hmm...seems to work for me (which is what I expected). As Frank noted, its easiest to avoid using a character appearing in the text as the "commmand delimter". Doing so means you don't have to go thru the tedious and error-prone step of "escaping" the delimiter. Thus:
fcat#: pg fsm
/asia/calcutta
/asia/bombay
fcat#:
fcat#: sed -e 's!/asia/calcutta!/india/!g' fsm
/india/
/asia/bombay
Note: having to "escape" the delimiter can be a royal pain....and you tend to see "cannot be parsed" errors. Too many things influence what is the "correct" number of "escapes", like "is this run from a command line" or "is this in a shell script" or others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2008 06:03 AM
10-20-2008 06:03 AM
Re: Search and replace Text in a File
Thanks for all your suggestions