- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Find and Replace command
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
04-09-2007 11:04 PM
04-09-2007 11:04 PM
i have created a file name like myfile.txt , Now i want to search a word in that file and replace with a new word without redirecting to another file.
N:B: i can do this in vi editor . but i want this from outside ( using the file itself)
Mridul
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 11:33 PM
04-09-2007 11:33 PM
SolutionOne possible way is to using sed, then writing into another file, then moving back to original file.
# cat 1
senthil
# sed s/senthil/prabu/g 1 > 2; mv 2 1;
# cat 1
prabu
P.S:
Not the best solution
HTH,
Prabu.S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 11:35 PM
04-09-2007 11:35 PM
Re: Find and Replace command
Without re-directing to another file - I have not noticed yet.
We normally use sed as below:
sed 's/oldtext/newtext/g' filename
But of course, you need to redirect it to a file if you want to save it - there is no online saving on sed as far as I know.
ed is an option (by automating the steps).
Rasheed Tamton.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 11:36 PM
04-09-2007 11:36 PM
Re: Find and Replace command
aap
noot
mies
$ perl -pi -e 's/noot/vuur/' xx
$ cat xx
aap
vuur
mies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2007 11:42 PM
04-09-2007 11:42 PM
Re: Find and Replace command
you can use perl:
#perl -i.del -ple "s/find/replace/" filename
generates an old file named filename.del. after you replaced every file you can delete all *.del files.
Hope this helps
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2007 12:08 AM
04-10-2007 12:08 AM
Re: Find and Replace command
# ex -s +'%s/search_word/replace_word/g | wq' infile
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2007 07:45 PM
04-10-2007 07:45 PM
Re: Find and Replace command
by vi is possibile to change by command line:
vi -c "%s/search_word/replace_word/g|wq" file.in
HTH,
Art