- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Replacing strings in a file at certain line number...
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-13-2002 04:54 AM
09-13-2002 04:54 AM
For example, I need to replace string '123' with '456' but only at the lines 10, 15 and 40, no where else in the file?
Any ideas?
Cheers
Russ.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2002 04:59 AM
09-13-2002 04:59 AM
Re: Replacing strings in a file at certain line numbers?
This can be done throughout the file using sed
(sed s/123/456/g file_name), but at specific line numbers is quite difficult, let me try and come back to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2002 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2002 05:05 AM
09-13-2002 05:05 AM
Re: Replacing strings in a file at certain line numbers?
If you have multiple occurances of the "old" string that you want substituted by the "new" string on a line, add the 'g' flag for global replacement. Otherwise, only the first occurance per line will be replaced (substituted).
sed -e $X's/old/new/g' filein > fileout
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2002 05:08 AM
09-13-2002 05:08 AM
Re: Replacing strings in a file at certain line numbers?
sed -n 's/123/456/,10p'
sed -n 's/123/456/,15p'
sed -n 's/123/456/,40p'
if you wanted to do lines 15 THROUGH 40, it would be like this:
sed -n 's/123/456/,15,40p'
HTH
mark