LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   sed regex (http://www.linuxquestions.org/questions/programming-9/sed-regex-903111/)

say_hi_ravi 09-15-2011 01:43 AM

sed regex
 
Below is the extract of one file where there are many similar entries.

Code:

$cat file1
| weblogic | bakejo | user1@example.com | user1@example.com | managed_server_lonlx10404.example.com_1_lonlx10404.example.com:8380 | managed_server_lonlx20491.example.com_2_lonlx20491.example.com:8380 |
| weblogic | bakejo | user1@example.com | user1@example.com | lonlx10404.example.com | lonlx20491.example.com |

I want to replace a pattern starting with managed and ending with second .com ( for example "managed_server_lonlx20491.example.com_2_lonlx20491.example.com") with only "managed".

i.e. final output should look like this
Code:

$cat file1
| weblogic | bakejo | user1@example.com | user1@example.com | managed:8380 | managed:8380 |
| weblogic | bakejo | user1@example.com | user1@example.com | lonlx10404.example.com | lonlx20491.example.com |

I tried to use sed

$sed -ne 's/managed_server_*_2_*.com/managed/p' file1

which did not work:(. I am sure taht I am not using correct regex. Please help.

druuna 09-15-2011 01:51 AM

Hi,

You are using a star (*) to capture a range, that should be dot star (.*):
Code:

sed 's/managed_server_.*_2_.*\.com/mamaged/g' infile
If you do want to look for dot com (.com) that dot needs to be taken literally and thus be escaped (\.com).

Hope this helps.

say_hi_ravi 09-15-2011 02:06 AM

druuna,

Yes, indeed it helped. many thanks :)

druuna 09-15-2011 02:12 AM

You're welcome :)


All times are GMT -5. The time now is 03:02 AM.