sed - search and replace whole string which contains dot


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed - search and replace whole string which contains dot
# 1  
Old 05-03-2015
sed - search and replace whole string which contains dot

Hello.

I would like to search exactly "string1.string2.string3" and replace it by "new_string1.new_string2.new_string3"
And
I would like to search exactly "string2.string3" and replace it by "new_string2.new_string3"
And
I would not found in the result : "string1.new_string2.new_string3" because "string2.string3" is different from "string1.string2.string3"

"string1.string2.string3" are email address like firstname_1.firstname_2.name@subdomain.domain.ext

"string2.string3" are email address like firstname.name@subdomain.domain.ext

So if size is different, a match should not apply in "string1.string2.string3" when search is done with "string2.string3"

How to do that ?
Code:
sed '/\<tring1.string2.string3\>/something_else/g'    # dose not work.
sed '/\btring1.string2.string3\b/something_else/g'     # dose not work.
sed '/\<tring1\.string2\.string3\>/something_else/g'  # dose not work.

Any help is welcome

Last edited by vbe; 05-03-2015 at 09:53 AM.. Reason: code tags
# 2  
Old 05-03-2015
Hi,
A possible syntax, but line mustn't begin with the string to search (not tested):
Code:
sed 's/\([[:space:]]\)string1\.string2\.string3@/\1new_string1.new_string2.new_string3@/g'

Regards.
This User Gave Thanks to disedorgue For This Post:
# 3  
Old 05-03-2015
You need to specify the character(-set) that is before the beginning of the string.
If there is nothing before - the string is at the beginning of the line - then give ^.
Code:
sed '/^string1\.string2\.string3@/something_else@/'

The same with the character after the end that is @ (and because it is cut it needs to be added again).

Last edited by MadeInGermany; 05-03-2015 at 02:24 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 05-04-2015
I guess the longer search string is not the problem as it would not modify the shorter one; it is vice versa. The real discriminator is the dot in front of "string2". Try
Code:
sed 's/[^.]string2\.string3/new_string2.new_string3/g' file

It would leave three element addresses alone. You may want to add the "@" to the end to make sure it only acts on e-mail addresses.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

2. Shell Programming and Scripting

How to search and replace string in column in file with command sed?

how to search and replace string in column in file with command sed or other search "INC0000003.in" and replace column 4 = "W" $ cat file.txt INC0000001.in|20150120|Y|N|N INC0000002.in|20150120|Y|N|N INC0000003.in|20150120|Y|N|N INC0000004.in|20150120|Y|N|Noutput... (4 Replies)
Discussion started by: ppmanja3
4 Replies

3. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

4. Shell Programming and Scripting

How to use SED or AWK to search and replace an exact string

I have a file DS1 DDS DS I want to replace only "DS" to "DSmail.blah.com" in a lot of files. I tried sed 's/DS/DSmail.blah.com' but it changes all the lines . thanks in advance (2 Replies)
Discussion started by: gubbu
2 Replies

5. Shell Programming and Scripting

awk/sed string search and replace

Need help with either sed or awk to acheive the following file1 ----- In the amazon forest The bats eat all the time... mon tue wed they would eat berries In the tropical forest The bats eat all the time... on wed bats eat nuts In the rain forest The bats eat all the time... on... (2 Replies)
Discussion started by: jville
2 Replies

6. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

7. Shell Programming and Scripting

Search, replace string in file1 with string from (lookup table) file2?

Hello: I have another question. Please consider the following two sample, tab-delimited files: File_1: Abf1 YKL112w Abf1 YAL054c Abf1 YGL234w Ace2 YKL150w Ace2 YNL328c Cup9 YDR441c Cup9 YDR442w Cup9 YEL040w ... File 2: ... ABF1 YKL112W ACE2 YLR131C (9 Replies)
Discussion started by: gstuart
9 Replies

8. UNIX for Dummies Questions & Answers

Search for a string and replace the searched string in the same position in samefile

Hi All, My requisite is to search for the string "0108"(which is the year and has come in the wrong year format) in a particular column say 4th column in a tab delimited file and then replace it with 2008(the correct year format) in the same position where 0108 was found in the same file..The... (27 Replies)
Discussion started by: ganesh_248
27 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

Need to replace all occurences of a search string using sed

All, Here is what I am searching for using sed. 1 00640000106798 I want to replace that with the following. 8 0064B0000106798 I can do this easy enough from the command line using sed but I need to put the search string in a file and then execute the sed command within a... (2 Replies)
Discussion started by: mjs3221
2 Replies
Login or Register to Ask a Question