LinuxQuestions.org
Register a domain and help support LQ
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 07-20-2008, 07:08 AM   #16
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83

Ghostdog74, that was exactly my point about regular expressions being potentially too inclusive.

By matching only valid characters (or avoiding invalid characters) you reduce issues later.

Example, to search for test followed by any number(including zero) of any character (excluding spaces and \ characters), followed by a .iso:

sed -i.bak 's/test[^ \]*\.iso/test0123-new.iso/' test.vmx

As we only want to exclude spaces and \ characters, this is shorter than my previous example, while still only finding valid matches.

EDIT:-

If you want to match a full stop you need to escape it (using \) EG: \.

Last edited by Disillusionist; 07-20-2008 at 07:15 AM.
 
Old 07-20-2008, 08:01 AM   #17
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
that's why my own preferred method is using fields and not worrying about regular expressions and its always the last field i want to change. well anyway, OP has got a solution, so it should be fine.
 
  


Reply

Tags
charachters, sed


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
Replacing "function(x)" with "x" using sed/awk/smth Griffon26 Linux - General 3 11-22-2006 11:47 AM
Using "sed" - a simple explanation needed midiox Linux - Newbie 2 04-03-2006 07:47 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 01:34 AM
KPPP "Query Modem" returns empty fields ananya Linux - Hardware 2 02-21-2005 11:50 PM
KPPP "Query Modem" returns empty fields ananya Linux - Software 1 02-21-2005 11:39 PM


All times are GMT -5. The time now is 10:54 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