Discussion:
sed regular expression help
Davis, Brent
2015-05-21 20:52:09 UTC
Permalink
I am still getting into regular expressions so I am still somewhat fresh, but I am stuck on a particular expression. I use the regexr.com site, which is extremely helpful to test, and I have bounced off other forums but everything I try I can't get this expression to work. For any seasoned people out there, this will probably be quick and dirty.


I want to filter out the following characters underline: BEFORE.....: `date --date=2015-01-10 '+%D'`

The expression I have built is sed -e "/\'\W%D\'\`/g". I get no errors or anything, but my output still has the characters in underline. I have tried sed -e "/[']\W%D['][`]/g", still the same thing. No errors but the characters are still there. Like I said, I tested this on regexr.com, and either works no problem. Any ideas out there?

Thanks
Brent
--
redhat-list mailing list
unsubscribe mailto:redhat-list-***@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
Joshua Gimer
2015-05-21 22:25:45 UTC
Permalink
Another slash?

s/match regex/replace value/options

s/\'\W%D\'\`//g

Also I didn't see anything underlined in your email. Need clarification on
what you are trying to remove, to fully assist.

Thanks,
Josh
Post by Davis, Brent
I am still getting into regular expressions so I am still somewhat fresh,
but I am stuck on a particular expression. I use the regexr.com site,
which is extremely helpful to test, and I have bounced off other forums but
everything I try I can't get this expression to work. For any seasoned
people out there, this will probably be quick and dirty.
`date --date=2015-01-10 '+%D'`
The expression I have built is sed -e "/\'\W%D\'\`/g". I get no errors
or anything, but my output still has the characters in underline. I have
tried sed -e "/[']\W%D['][`]/g", still the same thing. No errors but the
characters are still there. Like I said, I tested this on regexr.com,
and either works no problem. Any ideas out there?
Thanks
Brent
--
redhat-list mailing list
?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
--
Thanks,
Joshua Gimer

---------------------------

http://www.linkedin.com/in/jgimer
http://twitter.com/jgimer
--
redhat-list mailing list
unsubscribe mailto:redhat-list-***@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
Davis, Brent
2015-05-22 14:56:44 UTC
Permalink
Yea sorry about that. My co-worker mentioned that the underlined wouldn't come through.

The '+%D'` is what I had underlined.

I thought I had tried the regex before and it didn't work. I just tried it again, and same thing.



sed -e "s/\'\W%D\'\`//g;/skipping/d"


BEFORE.....: `date --date=2015-01-10 '+%D'`
AFTER......: `date --date=2015-01-01 '+%D'`







-----Original Message-----
From: redhat-list-***@redhat.com [mailto:redhat-list-***@redhat.com] On Behalf Of Joshua Gimer
Sent: Thursday, May 21, 2015 5:26 PM
To: General Red Hat Linux discussion list
Subject: Re: sed regular expression help

*** This is an EXTERNAL email. STOP. THINK before you CLICK links or OPEN attachments. ***


Another slash?

s/match regex/replace value/options

s/\'\W%D\'\`//g

Also I didn't see anything underlined in your email. Need clarification on what you are trying to remove, to fully assist.

Thanks,
Josh
Post by Davis, Brent
I am still getting into regular expressions so I am still somewhat
fresh, but I am stuck on a particular expression. I use the
regexr.com site, which is extremely helpful to test, and I have
bounced off other forums but everything I try I can't get this
expression to work. For any seasoned people out there, this will probably be quick and dirty.
`date --date=2015-01-10 '+%D'`
The expression I have built is sed -e "/\'\W%D\'\`/g". I get no
errors or anything, but my output still has the characters in
underline. I have tried sed -e "/[']\W%D['][`]/g", still the same
thing. No errors but the characters are still there. Like I said, I
tested this on regexr.com, and either works no problem. Any ideas out there?
Thanks
Brent
--
redhat-list mailing list
?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
--
Thanks,
Joshua Gimer

---------------------------

http://www.linkedin.com/in/jgimer
http://twitter.com/jgimer
--
redhat-list mailing list
unsubscribe mailto:redhat-list-***@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
--
redhat-list mailing list
unsubscribe mailto:redhat-list-***@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
Cameron Simpson
2015-05-22 22:19:00 UTC
Permalink
Post by Davis, Brent
Yea sorry about that. My co-worker mentioned that the underlined wouldn't come through.
The '+%D'` is what I had underlined.
I thought I had tried the regex before and it didn't work. I just tried it again, and same thing.
sed -e "s/\'\W%D\'\`//g;/skipping/d"
BEFORE.....: `date --date=2015-01-10 '+%D'`
AFTER......: `date --date=2015-01-01 '+%D'`
1: Please don't top post, and please trim the quoted material for relevance.

2: Please make clear what output you want after the sed command runs. The above
seems to should a failed run (no change). Please give an example of what a
successful run would do.

3: Inside double quotes the backslash is special. Use single quotes; they a re
FAR more reliable when working with regexps on the comman line. If you need to
use a single quote in the expression, leaves quotes, quote the single quote,
return to quotes, eg:

sed 's/foo'\''bar/foo-ach-bah/'

which represents:

s/foo'bar/foo-ach-bag/

inside sed.

4: You can put sed commands into a file, avoid all quoting issues. For example
you can put the "raw" sed command(s) in a file "foo.sed" an go:

sed -f foo.sed

which avoids a lot of quoting pain.

You also write:

Like I said, I tested this on regexr.com, and either works no problem

5: Any regexp tester is VERY dependent on the flavour of regexp in use: basic
regexps, full regexps, sed regexps (basic or full depending on options), perl
compatible regexps, etc etc. They're great for finding logical errors, less so
for subtle quoting or dialect errors.

Cheers,
Cameron Simpson <***@zip.com.au>

Don't have awk? Use this simple sh emulation:
#!/bin/sh
echo 'Awk bailing out!' >&2
exit 2
- Tom Horsley <***@csd.harris.com>
--
redhat-list mailing list
unsubscribe mailto:redhat-list-***@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
Loading...