- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to replace a string in a particular line using...
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
07-24-2004 10:03 PM
07-24-2004 10:03 PM
How to replace a string in a particular line using SED
I have a file(text) file and want to replace a part of string with another string. I've got SED running on a Win XP PC but are having trouble with the syntax.....
For example
*************
File contents
ProductKey= "aaaaa-aaaaa-aaaaa-aaaaa-aaaaa"
The above line is somewhere in the middle of the file,which contains around 100 lines.
I am unable to point to that particular line and replace it.
I have written a script , that prompts for the string to be replaced and if the input is bbbbb-bbbbb-bbbbb-bbbbb-bbbbb (without the quotation marks as in the target file), then the file should be updated as shown below.
ProductKey= "bbbbb-bbbbb-bbbbb-bbbbb-bbbbb"
Please help me to work this one out...
Cheers,
Dave.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 11:08 PM
07-24-2004 11:08 PM
Re: How to replace a string in a particular line using SED
sed s/string to replace/replacement/ filename
where filename is the name ot the file for which you do the replacement.
If there's more than one occurence of such string you can use :
s/string to replace/replacement/g filename
this will replace all occurences of founded string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 11:14 PM
07-24-2004 11:14 PM
Re: How to replace a string in a particular line using SED
sed 's/aaaa/bbbb/' file.txt > changed_file.txt
br Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 11:28 PM
07-24-2004 11:28 PM
Re: How to replace a string in a particular line using SED
ProductKey= "kjkfd-dfdsf-sfrws-dfdfd-fdfdf"
The string will always be 29 characters in length and will be preceeded by a quotation mark and followed by a quotation mark.
Help appreciated....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 11:45 PM
07-24-2004 11:45 PM
Re: How to replace a string in a particular line using SED
ex -- if file g.test contains
-----------begin of file--------------
aa
bb
aaaaa-aaaaa-aaaaa-aaaaa-aaaaa
cc
dd
-----------end of file----------------
then type the following
shell_prompt > sed -e s/aaaaa-aaaaa-aaaaa-aaaaa-aaaaa/bbbbb-bbbbb-bbbbb-bbbbb-bbbbb/g g.test
this will display the g.test file and replace the aaa... by bbb..., mind you this does not change the content of the g.test file this interactive form of sed just display the change ! but this is good for testing..
The s/'orig_sting'/repl_string'/g placed in a sed command file will do the substitution for you the /g at the end stands for global (this is if you want to replace every occurence of the string"
Hope this get you codeding.
Jean-Pierre
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 11:52 PM
07-24-2004 11:52 PM
Re: How to replace a string in a particular line using SED
sed "s/ProductKey=.*/ProductKey=aaabbbccdd/g" filename
will do the job...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2004 11:57 PM
07-24-2004 11:57 PM
Re: How to replace a string in a particular line using SED
But Alexander 2 reply seem right to me
Sorry about my slow typing.
Jean-Pierre