The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
match nearest bogu0001 UNIX for Dummies Questions & Answers 1 02-13-2009 04:42 AM
pattern match tostay2003 Shell Programming and Scripting 3 12-31-2008 01:47 PM
awk or sed for finding closest pattern to a line number alirezan Shell Programming and Scripting 1 10-11-2008 07:08 AM
how do i pattern match a field with awk? someone123 Shell Programming and Scripting 4 06-03-2008 09:08 AM
pattern match and substitution, can you help? frustrated1 Shell Programming and Scripting 4 02-20-2006 08:48 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2009
sudheer1984 sudheer1984 is offline
Registered User
  
 

Join Date: Jun 2009
Posts: 3
sed match closest/nearest pattern

All
i am struggling to raplace some text in a line between two (closest) patterns ,
Code:
line="/home/usr/bin/:/home/usr/devuser,n1.9/bin:/home/usr/root/bin"
i want to replace "devuser,n1.9" with "NEWVAL", basically all teh text from "devuser" until nearest '/' with some new text.

i tried teh following
Code:
echo $line | sed 's/devuser.*\//NEWVAL\//'
i am getting /home/usr/bin/:/home/usr/NEWVAL/bin"

where i am expecting
/home/usr/bin/:/home/usr/NEWVAL/bin:/home/usr/root/bin"

i know sed will match the longest possible pattern, i tried this as well
Code:
echo $line | sed 's/devuser.*[^\/]/NEWVAL/'
but still no luck

any help will be appreciated.

Thanks in advance.

---------- Post updated at 02:13 AM ---------- Previous update was at 01:30 AM ----------

hey guys,
found something
Code:
echo $line | sed 's/devuser[^\/]*/NEWVAL/'
is giving me the expected output.

any other suggestions are welcome.

Last edited by otheus; 07-02-2009 at 04:59 AM.. Reason: added code tags
Bits Awarded / Charged to sudheer1984 for this Post
Date User Comment Amount
07-02-2009 otheus posting own solution 500
  #2 (permalink)  
Old 07-02-2009
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
I think you found THE answer. PLEASE use [code] tags.
Reply

Bookmarks

Tags
sed nearest mtach between two words

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0