LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-15-2011, 02:43 AM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 68

Rep: Reputation: 15
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.
 
Old 09-15-2011, 02:51 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
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.
 
1 members found this post helpful.
Old 09-15-2011, 03:06 AM   #3
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 68

Original Poster
Rep: Reputation: 15
druuna,

Yes, indeed it helped. many thanks
 
Old 09-15-2011, 03:12 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374Reputation: 2374
You're welcome
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] sed regex schneidz Programming 1 02-28-2011 07:46 PM
Help with sed regex homer_3 Linux - General 1 08-18-2009 02:57 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 06:10 AM
sed / regex question whysyn Linux - General 3 06-28-2005 03:11 PM
Help with Sed and regex cmfarley19 Programming 6 11-18-2004 02:09 PM


All times are GMT -5. The time now is 06:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration