Problem with sed and negative regexpr's


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with sed and negative regexpr's
# 1  
Old 02-22-2008
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?
# 2  
Old 02-23-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

sed Or Grep Problem OR Terminal Problem?

I don't know if you guys get this problem sometimes at Terminal but I had been having this problem since yesterday :( Maybe I overdid the Terminal. Even the codes that used to work doesn't work anymore. Here is what 's happening: * I wanted to remove lines containing digits so I used this... (25 Replies)
Discussion started by: Nexeu
25 Replies

2. UNIX for Dummies Questions & Answers

Sed/awk to find negative numbers and replace with 1?

Greetings. I have a three column file, and there are some numbers in the second column that are <1. However I need all numbers to be positive, thus need to replace all those numbers with just one. I feel like there must be a simple way to use awk to find these numbers and sed to replace but can't... (5 Replies)
Discussion started by: Twinklefingers
5 Replies

3. Post Here to Contact Site Administrators and Moderators

Bits in Negative

Hi All, I have received a notification that I have posted a question double times. But I have not done all this intentionally. I have just joined this site and was not aware of the rules. Also I have my bits in negative. what does that mean. Thanks (1 Reply)
Discussion started by: Palak Sharma
1 Replies

4. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

5. Shell Programming and Scripting

change value to negative

How to change value in column 5 to negative based on value in column 2 ? Example: For all records with A in column 2 change value in column 5 to negative. file Code: 1234~A~b~c~10~e~f~g~h~09/10/09 1234~A~b~c~75~e~f~g~h~11/12/10 1234~A~b~c~40~e~f~g~h~12/06/10 5678~B~b~c~2~e~f~g~h~01/11/11... (4 Replies)
Discussion started by: sigh2010
4 Replies

6. UNIX for Dummies Questions & Answers

Snmp Disk Problem = Negative Values

Ok, so i monitor disk space on remote machines using snmp. Works great for me. But whenever a particular partition happens to have Terabytes of data, snmp starts reporting negative values. Can someone please tell me how to get around this problem? The AllocationUnit is 512 bytes. Weird... (0 Replies)
Discussion started by: SkySmart
0 Replies

7. Shell Programming and Scripting

retain negative value through sed command

Hi Experts , We have a reuirement that we have to remove multiple comma's within double quotes in the columns as we have already taken care through our sed command . Here is my code :- sed -e ':a' -e 's/\("*\),\(*"\)/\1\2/;ta' $Orign_File > $dummy sed 's/"//g' $dummy > $Process_file ... (14 Replies)
Discussion started by: bshivali
14 Replies

8. Shell Programming and Scripting

Regexpr expertise required

Any experts on regular expressions out there, can you help me rationalise this? In this post: - https://www.unix.com/shell-programming-scripting/121977-writing-algorithm-recode-data-points-2.html I use the code: - tmp = $1 ; gsub(/00/, ".") ; $1 = tmp tmp = $1 ;... (2 Replies)
Discussion started by: steadyonabix
2 Replies

9. Programming

Negative Offset

Function: int fcntl(int fd, int cmd, struct flock * lock) Data Type: struct flock This structure is used with the fcntl function to describe a file lock. It has these members: off_t l_start This specifies the offset of the start of the region to which the lock applies, and... (1 Reply)
Discussion started by: DNAx86
1 Replies

10. UNIX for Dummies Questions & Answers

negative permissions

Hi. I want to know how can I negate a write permission for a file to an expecific user when that user have that permission becouse he belongs to a group what have a write permission for the file. (4 Replies)
Discussion started by: sickoboy
4 Replies
Login or Register to Ask a Question