You are not logged in.

#1 2010-04-29 22:06:28

ShadowKyogre
Member
From: Hell! XP No... I'm not telling
Registered: 2008-12-19
Posts: 476
Website

Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

As the title says, I'm working on a zenity script to store a fair chunk of sample sed commands to remind myself what I can do with it. Everything seems to work fine except for the l33t to english garbler.

When that is run, it gives me this:

sed: -e expression #1, char 9: unterminated `s' command
sed: -e expression #1, char 7: unknown option to `s'
sed: -e expression #1, char 10: unterminated `s' command
sed: -e expression #1, char 5: unterminated `s' command 
sed: -e expression #1, char 8: unterminated `s' command

http://pastebin.org/193208 <-- has whole script and highlighted line causing trouble <-- not updated, but I have it solved on the local copy. I'll make sure to update this when I get done cleaning up the code
[^edit: escaped characters pointed out]

But if I execute this (same trouble command, but not inside the script) [fixed typo now]:

sed s/'\/-\\'/A/g <yourfile that has /-\ for a in it>
or
echo "/-\\" | sed s/'\/-\\'/A/g

^It turns the /-\ back into an A...so...I honestly don't know what the shell is doing to interpret the same command differently.

Last edited by ShadowKyogre (2010-05-02 18:34:30)


For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page

Offline

#2 2010-04-29 22:33:49

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

Your quoting is wrong.

Offline

#3 2010-04-29 22:49:11

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

The quoting is indeed a mess! But the error is from lack of escaping, and no amount of quoting will fix that.

EDIT
Although in the script you have: sed s/'\/-\\'/A/g, which is different from what you posted above.

There is an error in:
sed s/'[_-'/G/g
sed s/'[]'/O/g
sed s/'\/'/ V/g
sed s/'\|/'/W/g

So unescaped []/. And probably some more from special regex characters.

Last edited by Procyon (2010-04-29 23:03:46)

Offline

#4 2010-04-29 23:29:12

ShadowKyogre
Member
From: Hell! XP No... I'm not telling
Registered: 2008-12-19
Posts: 476
Website

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

Daenyth wrote:

Your quoting is wrong.

Procyon wrote:

The quoting is indeed a mess! But the error is from lack of escaping, and no amount of quoting will fix that.

EDIT
Although in the script you have: sed s/'\/-\\'/A/g, which is different from what you posted above.

There is an error in:
sed s/'[_-'/G/g
sed s/'[]'/O/g
sed s/'\/'/ V/g
sed s/'\|/'/W/g

So unescaped []/. And probably some more from special regex characters.

*looks back at the script and my post* Whoooooooooah...that is a huge mistake o_o. *hurries to escape the regex characters in the l33t*
I'll go fix the typo in my post and I went around and escaped the ones you showed. Now only this pops up.

sed: -e expression #1, char 7: unterminated `s' command

For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page

Offline

#5 2010-05-01 12:08:46

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

Well, without seeing your updated script I can't say for sure what's still messed up, but here's another tip: you don't need to spawn 26 instances of sed to do this.

You can replace:

sed s/'\/-\\'/A/g "$txt" | \
sed s/'|3'/B/g | \
sed s/'('/C/g | \
sed s/'|)'/D/g | \
sed s/'\&'/E/g | \
sed s/'|='/F/g | \
...
sed s/'>_'/Z/g > /tmp/lookup2.txt

With this:

sed -e s/'\/-\\'/A/g \
    -e s/'|3'/B/g    \
    -e s/'('/C/g     \
    -e s/'|)'/D/g    \
    -e s/'\&'/E/g    \
    -e s/'|='/F/g    \
...
    -e s/'>_'/Z/g "$txt" > /tmp/lookup2.txt

Also tip: if one regex is giving you that error, then remove them one-by-one until the error goes away; then you know which one is giving you the problems.

Offline

#6 2010-05-01 15:17:07

tlvb
Member
From: Sweden
Registered: 2008-10-06
Posts: 297
Website

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

or

sed 's/\/-\\/A/g;s/|3/B/g;s/(/C/g; ...

even, sed commands can be chained with a semicolon, also I always quote the whole script (out of habit)..


I need a sorted list of all random numbers, so that I can retrieve a suitable one later with a binary search instead of having to iterate through the generation process every time.

Offline

#7 2010-05-01 19:59:35

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

If the pattern contains "/" you can change the delimiter char to something (anything else, I think) else, eg %

sed 's%/-\\%A%g'

See info sed for details: The "s" Command.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#8 2010-05-02 18:33:37

ShadowKyogre
Member
From: Hell! XP No... I'm not telling
Registered: 2008-12-19
Posts: 476
Website

Re: Writing up short showcase for sed, but /-\ -> A doesn't work [SOLVED]

skanky wrote:

If the pattern contains "/" you can change the delimiter char to something (anything else, I think) else, eg %

sed 's%/-\\%A%g'

See info sed for details: The "s" Command.

Hey, it works now! Wonder how come I didn't catch that when I was reading info sed lol

tlvb wrote:

or

sed 's/\/-\\/A/g;s/|3/B/g;s/(/C/g; ...

even, sed commands can be chained with a semicolon, also I always quote the whole script (out of habit)..

Okay, going back to the script and cleaning up the code.


For every problem, there is a solution that is:
Clean
Simple and most of all...wrong!
Github page

Offline

Board footer

Powered by FluxBB