The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Negative Offset DNAx86 High Level Programming 1 05-09-2008 05:04 PM
C++ how to isdigit() a negative number? Darklight High Level Programming 1 04-22-2008 12:01 PM
negative permissions sickoboy UNIX for Dummies Questions & Answers 4 10-12-2006 06:49 PM
RegExp negative match not working umen Shell Programming and Scripting 2 08-22-2006 01:57 PM
negative UID/GID?!! I can see 'em but what the hell do they mean?! hellz UNIX for Dummies Questions & Answers 2 09-07-2001 12:18 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-22-2008
Registered User
 

Join Date: Feb 2008
Posts: 1
Stumble this Post!
Problem with sed and negative regexpr's

I have a file with various syntax that I'm try to run sed on to change over a specific regexp and having problems. I want to swap all instances of a token so long as the token isn't followed by either an alphanumeric character, an underscore, or an exclamation point.

The test file looks like this:
test
test4
testF
test!
test;test

I'm trying to run sed like this
% sed -e 's/test[^[:alnum:]&^_&^\!]/FFF/g' test

What I see is this which is close but not exactly what I'm looking for:
test
test4
testF
test!
FFFtest

Notice the last entry does not have a ";" between FFF and test. Is there something I can use in the replace string to represent that I want to print out the negated matched expression found?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-23-2008
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Stumble this Post!
Code:
$ sed 's/^test\([^A-Za-z0-9_!]\)/FFF\1/' testfile 
test
test4
testF
test!
FFF;test
EDIT: To elaborate a bit, yes - the \(...\) in the LHS stores the matched negated regex result, which is printed in the RHS with \1.

Cheers,
ZB
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0