GnuWin32 sed 4.1.4 regexp matching


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers GnuWin32 sed 4.1.4 regexp matching
# 1  
Old 06-22-2005
GnuWin32 sed 4.1.4 regexp matching

I am using GnuWin32 sed and am having trouble with the regexp - i.e., they don't behave the same way as in UNIX (POSIX and and all that). I have a stream of data, e.g.:

11111'222?'22'33?'333'44444'55555'

I want to insert a \n after those apostrophes that are *not* preceded by a ?.

Expected output:

11111'
222?'22'
33?'333'
44444'
55555'

I used the substitution:

s/\([^?]\)'/\1'\n/g

this should be OK but it didn't work... it replaced those that *did* have a ? in front - I want the opposite.

Any gurus with a suggestion? (apart from sticking to UNIX)
# 2  
Old 06-22-2005
I can't imagine that that code did what you want in Unix either.

You need to escape your single quotes for them to be recognised as characters in the file and not as quotes around part of the command.
# 3  
Old 06-23-2005
Seems to work fine...
Code:
$ sed --version
GNU sed version 4.1.4
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

$ head file1 sed1
==> file1 <==
11111'222?'22'33?'333'44444'55555'

==> sed1 <==
s/\([^?]\)'/\1'\n/g

$ sed -f sed1 file1
11111'
222?'22'
33?'333'
44444'
55555'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with sed and regexp

Hi everyone, I would really appreciate any help I could get on the following topic. I am not very familiar with reg expressions nor with sed, I just know the basic uses. What I am trying to do is the following: I have a huge text file where I would like to replace all occurnces of a certain... (13 Replies)
Discussion started by: Boxtuna
13 Replies

2. Shell Programming and Scripting

[gnuwin32] sed & variable %TIME%

HI.. I made ".bat" in windows 2003 , with set TIEMPO1= %TIME% | sed -e "s/://g" -e "s/,//g" echo valor de tiempo1 = %TIEMPO1% when i execute this, the result is but if i open cmd, and execute en line command this.. G:\>echo %TIME% | sed -e "s/://g" -e "s/,//g" 12390841 anyone have... (5 Replies)
Discussion started by: upszot
5 Replies

3. Shell Programming and Scripting

matching regexp

Hi, maybe it is stupid question, but is it possible to match expression like this ? : ... // ... ( there is "//" somewhere on the line and on the end of the line there ISN'T "*/" ) I've tried something like : (in SED) sed 's/\/\/' but I need "*/" not to be on the end of the line ...... (2 Replies)
Discussion started by: kolage
2 Replies

4. Shell Programming and Scripting

perl regexp: matching the parent xml tag

Hi folks. I would like to remove the full parent (outer) xml tag from a file given a matching child (inner) tag, in a bash shell. To be more specific, this is what I have so far: $ cat myFile.xml <Sometag></Sometag> <Outer> <Inner>1</Inner> </Outer> <Outer> <stuff>alot</stuff> ... (3 Replies)
Discussion started by: BatManWSL
3 Replies

5. Shell Programming and Scripting

perl regexp matching

Hello, I cannot see what's wrong in my code. When I run code below, it just print an empty string. my $test = "SWER~~ERTGSDFGTHAS_RTAWGA_DFAS.x4-234253454.in"; if ($test = ~ m/\~{1,2}.*4/) { print "$1\n"; } else { print "No match...\n"; } Anyone know what I'm doing wrong? ... (4 Replies)
Discussion started by: urandom
4 Replies

6. UNIX for Dummies Questions & Answers

sed before and after regexp

Dear all i have the code which print 1 line of context before and after regexp, with line number sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h the code work well but any one can tell me what each letter mean {=;x;1!p;g;$!N;p;D;} also how i can print 2 line before and onle line after ... (2 Replies)
Discussion started by: soly
2 Replies

7. Shell Programming and Scripting

sed regexp

Hi, I am not that good with reg exp and sed. But I was just looking at something the other day and came across a situation. When I ran the below command: echo "123 word" | sed 's/*/(&)/' the op was: (123) word But when I ran: echo "123 word" | sed 's/*/(&)/g' the o/p was: (123)... (4 Replies)
Discussion started by: King Nothing
4 Replies

8. Shell Programming and Scripting

Using SED on Windows xp-GnuWin32

I installed the GnuWin32 tools on my Windows XP system but I cannot .. for the life of me .. get the SED tool to work for me. All I need to do is remove blank lines for a text file. My script is ... sed -e '/^$/ d' xxx.txt > yyy.txt The error msg is: sed: -e expression #1, char 1: unknown... (1 Reply)
Discussion started by: HOLMBERG
1 Replies

9. Shell Programming and Scripting

tcl: regexp matching special character

Hello Experts, Can someone help me here: I have a variable which contains a string with "". set var1 {a} set str1 {a is the element i want to match} Now "regexp $var1 $str1" does not work? ("regexp {a\} $str1" works, but var1 gets it's value automatically from another script) Is... (6 Replies)
Discussion started by: sumitgarg
6 Replies

10. Shell Programming and Scripting

regexp with sed again!!!

please help: I want to add 1 space between string and numbers: input file: abcd12345 output file: abcd 1234 The following sed command does not work: sed 's/\(+\)\(+\)/\1 \2/' file Any ideas, please Andy (2 Replies)
Discussion started by: andy2000
2 Replies
Login or Register to Ask a Question