![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| String replacement | mnmonu | Shell Programming and Scripting | 6 | 03-24-2009 07:22 AM |
| String replacement | reddybs | Shell Programming and Scripting | 7 | 01-22-2009 08:50 AM |
| Replacement of string | c0384 | Shell Programming and Scripting | 1 | 09-17-2008 11:06 AM |
| AWK String replacement | subin_bala | Shell Programming and Scripting | 5 | 07-16-2008 03:29 AM |
| sed problem - replacement string should be same length as matching string. | amangeles | Shell Programming and Scripting | 4 | 01-11-2006 06:11 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
String replacement using sed
I need to search and replace a particular string in a file. Only the exact match of the string should be replaced.
eg: File contents : abc abcd abcdef --> Replace only 'abc' with 'xyz', but it should not replace abcd with xyzd. So the o/p should be: xyz abcd abcdef. How can this be done? I tried sed 's/\<abc\>/xyz/g' , but it dint work. Any help would be appreciated. Thanks in advance! |
|
||||
|
Quote:
Code:
echo "string" | sed -e 's/ abc / xyz /g' | sed -e 's/^abc /xyz /g' -e 's/ abc$/ xyz/g' Hello i am not very sure how to do this using sed options , there could far better way though. ![]() In the above code i just took care about 1. abc at starting of the string 2. abc at end of the string 3. abc in between the string |
![]() |
| Bookmarks |
| Tags |
| exact, replace, seach |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|