01-20-2009
gnu sed regex grouping not working?
Hello,
from the gnu sed manual, I should be able to do this:
`\(REGEXP\)'
Groups the inner REGEXP as a whole, this is used to:
* Apply postfix operators, like `\(abcd\)*': this will search
for zero or more whole sequences of `abcd', while `abcd*'
would search for `abc' followed by zero or more occurrences
of `d'. Note that support for `\(abcd\)*' is required by
POSIX 1003.1-2001, but many non-GNU implementations do not
support it and hence it is not universally portable.
the version of sed I am using is gnu sed v 4.1.5
The feature mentioned above does not seem to be working; eg,
echo "abc-abc" | sed -r 's/[\(abc\)]/%/g'
gives:
%%%-%%%
If it were treating abc as grouped, I should get:
%-%
I have tried to get this feature to work on several different systems, and never have. I have done a fair amount of googling on this with no answers.
Ultimately what I would like to do is remove text between two strings, eg, <script and </script>, without being greedy. So I would like to be able to do something like:
sed 's/<script[^\(<\/script>\)]*<\/script>//g'
in order to only remove text between a <script string and the next </script> string without removing all the text clear to the last </script> string on the line.
An input on why this does not seem to be working for me would be greatly appreciated.
Allasso
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I run awk
cat $1|awk '{print $6}'
and get a lot of results and I want results to group them. For example my result is (o/p is unknown to user)
xyz
xyz
abc
pqr
xyz
pqr
etc
I wanna group them as
xyz=total found 7
abc=total ....
pqr=
Thank (3 Replies)
Discussion started by: pujansrt
3 Replies
2. Shell Programming and Scripting
Hi,
I have the following script :-
#!/bin/csh -f
set var="HOST2"
sed -e 's/\(.*TRANSFER TO\).*\(usr\)/\1 "$var" \2/' tempFile
tempFile contains:
STOP TRANSFER TO HOST1 /usr/bin/myscript
1. How to use variable in the above sed command. It replaces with $var... (6 Replies)
Discussion started by: angshuman_ag
6 Replies
3. Shell Programming and Scripting
I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly:
if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies
4. UNIX for Dummies Questions & Answers
Hi Forum
im trying to use grouping in a regex statement in a function in a script
this is the criteria im trying to match :It MUST have 3 character at the beginning. After that it can have a mix of spaces,alpha-numeric and dashes in any order
eg HUG this-stuff, FGU taylor-8-shoes, ZDFnintendo... (2 Replies)
Discussion started by: ShinTec
2 Replies
5. Shell Programming and Scripting
Hi,
I'm trying to validate if a string matches a regular expression, but it is not working. Am I missing something? Do I need to scape any of the characters?
if echo 'en-GB' | egrep '({1,8})(-{1,8})*' >/dev/null; then
echo Valid value
fi
Thanks in advance (6 Replies)
Discussion started by: skrtxao
6 Replies
6. Shell Programming and Scripting
Hello, would you please help me with why my SED command file is outputting the entire input file instead of only the text that I'm trying to block?
cat testfile
O 111111111-00
DUE-DATE
METHOD:
FREQUENCY:
O 222222222-00
DUE-DATE
METHOD:
FREQUENCY:
O 333333333-02
DUE-DATE
METHOD:... (4 Replies)
Discussion started by: lneedh1
4 Replies
7. Shell Programming and Scripting
I have below inside a file.
11.22.33.44
user1
11.22.33.55
user2
I need this manipulated as
alias server1.domain.com='ssh user1@11.22.33.44'
alias server2.domain.com='ssh user2@11.22.33.55' (3 Replies)
Discussion started by: anil510
3 Replies
8. UNIX for Dummies Questions & Answers
I have a number of files that I pass through awk/gsub.
I believe to have found a working regex and on 'test bed' sites it matches, however within gsub it does not.
Examples:
Initial data:
/Volumes/Daniel/Public/Drop Box/_Hellsing_Ultimate_OVA_-_10_.mkv
gsub & regex:
gsub("\]+\]",""
... (4 Replies)
Discussion started by: unknownn
4 Replies
9. Shell Programming and Scripting
I am using a regex to exactly match a string abcdef as ^abcdef$. But it does'nt seem to work :( (11 Replies)
Discussion started by: gaurav99
11 Replies
10. Shell Programming and Scripting
I'm just learning Regex and while testing my understanding I received some unexpected results.
I created example.txt with the text "abcddd". Running the command
grep --color 'd' example.txt
I received the results:
"abcddd" with the first and second letter d highlighted in red.
So... (1 Reply)
Discussion started by: rthomas529
1 Replies