Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Advanced Search and replace technique(help!)

Name: Anonymous 2010-04-20 5:38

                        <option value="Seller">Seller</option>
                        <option value="Seller2">Seller2</option>
                        <option value="xxx">Seller3</option>
                        <option value="xxx">sedfBFB</option>
                        <option value="xxx">Sedscdsa</option>
                        <option value="xxx">dfsdvs</option>
                        <option value="xxx">sg42gr</option>
On those line(plus many more ofcourse) I would like to replace xxx with the text that comes next, like the first two lines.
With simple replace of text editors this can be done.
Can this be done with emacs something like that?
Something like replace xxx with what is wrapped by > and </option>.Or just copy what is wrapped between two string would be enough.

Name: new to ``re`` module 2010-04-20 6:23

[code=python]
from re import match

def foo(s):
    def bar(gs):
        if len(gs) == 2 and gs[0] == "xxx":
            return s.replace("xxx", gs[1])
        return s
    return bar(match("\s*\<option value\=\"(\w+)\"\>(\w+)\<\/option\>\s*$", s).groups())

with open("src") as fs, open("dst", mode="w") as fd:
    fd.writelines(map(foo, fs.readlines()))
[/code]
It works, but doesn't fully satisfy me. Is there a neat way to get rid of that dumb replace?

Name: Anonymous 2010-04-20 6:24

Oh, Jesus! Terribly sorry!

from re import match

def foo(s):
    def bar(gs):
        if len(gs) == 2 and gs[0] == "xxx":
            return s.replace("xxx", gs[1])
        return s
    return bar(match("\s*\<option value\=\"(\w+)\"\>(\w+)\<\/option\>\s*$", s).groups())

with open("src") as fs, open("dst", mode="w") as fd:
    fd.writelines(map(foo, fs.readlines()))

Name: Anonymous 2010-04-20 6:32

>>2,3
It would have been much easier to just generate the text
>>> l = ["Seller","Seller2","Seller3","sedfBFB","Sedscdsa","dfsdvs","sg42gr"]
>>> for x in l: print '<option value="%s">%s</option>' % (x,x)
...
<option value="Seller">Seller</option>
<option value="Seller2">Seller2</option>
<option value="Seller3">Seller3</option>
<option value="sedfBFB">sedfBFB</option>
<option value="Sedscdsa">Sedscdsa</option>
<option value="dfsdvs">dfsdvs</option>
<option value="sg42gr">sg42gr</option>

Name: Anonymous 2010-04-20 7:32

Ugh... But this is not valid TURKEY solution. You'll have to generate your list l from actual data first anyway.

And look, all those records are indented. What if the whitespace layout makes sense? Just kidding.

Name: Anonymous 2010-04-20 7:42

This should be done inside the application itself, not in a text editor. e.g. on the js submit event:
$("#form").submit(function() { $("#select").val($("#select :selected").val()); });
Or if you fancy, in the PHP/ASP/Ruby/Whatever
<?php
    $options = new Array("Seller", "Seller2", "Seller3", "sedfBFB", "Sedscdsa", "dfsdvs", "sg42gr");
    foreach($i in $options) {
        echo "<option value=\"".$i."\">".$i."</option>\n"
    }
?>

Name: Anonymous 2010-04-20 7:46

>>6
To be clear, I was saying duplicating values is good way to create unmaintainable code and it is best if you have all your data, even form option value => text mappings stored in a single place. There are actually some PHP DOM plugins that help immensely with this problem, especially if you need to replicate and manipulate HTML in your PHP.
I've only ever actually needed to do this once (Form spamming web app that scraped a page and replicated the forms on it, allowing arbitrary user configuration and manipulation before repeatedly posting to the form URL) so if you need to go this far, you should probably rethink your entire design.

Name: Anonymous 2010-04-20 8:46

Holy shit, don't you guys know sed?

Name: Anonymous 2010-04-20 8:53

>>8
Don't help him Now he has two problems

Name: Anonymous 2010-04-20 9:04

>>9
Yes I anticipated that. Two smaller problems, in fact. It's the Unix way.

Name: Anonymous 2010-04-20 9:21

>>7
The best solution. Also, read SIWP.

Name: Anonymous 2010-04-20 9:29

I recommend you read up on XSLT. It's not a good solution to your problem, but it's good for a laugh.

Name: Anonymous 2010-04-20 11:34

>>12
XSLT
good solution

No.

Name: Anonymous 2010-04-20 11:47

>>13
XSLT
It's not a good solution
it's good for a laugh

Learn to read, moran.

Name: Anonymous 2010-04-20 13:40

Bah, this is EMAcs. Use a bloody keyboard macro.

Name: Anonymous 2010-04-20 14:06

[code]s/"(.*?)">(.*?)</"$2">$2</g[code]
Or similar, whatever, nobody cares.

Name: Anonymous 2010-04-20 14:34

C-M % ^.*?<option.*?>\(.*?\)</option> RET <option value="\1">\1</option> RET !

Name: Anonymous 2010-04-20 14:58

>>17
Is that VIM?

Name: Anonymous 2010-04-20 15:00

>>18
EMACS

Name: Anonymous 2010-04-20 16:17

>>18,19

When I log into my Xenix system with my 110 baud teletype, both vi and Emacs are just too damn slow. They print useless messages like, ‘C-h for help’ and ‘“foo” File is read only’. So I use the editor that doesn't waste my VALUABLE time.

Ed, man!  !man ed

ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.


Computer Scientists love ed, not just because it comes first alphabetically, but because it's the standard. Everyone else loves ed because it's ED!

“Ed is the standard text editor.”

And ed doesn't waste space on my Timex Sinclair. Just look:

-rwxr-xr-x  1 root          24 Oct 29  1929 /bin/ed
-rwxr-xr-t  4 root     1310720 Jan  1  1970 /usr/ucb/vi
-rwxr-xr-x  1 root  5.89824e37 Oct 22  1990 /usr/bin/emacs

Of course, on the system I administrate, vi is symlinked to ed. Emacs has been replaced by a shell script which 1) Generates a syslog message at level LOG_EMERG; 2) reduces the user's disk quota by 100K; and 3) RUNS ED!!!!!!

“Ed is the standard text editor.”

Let's look at a typical novice's session with the mighty ed:

golem$ ed

?
help
?
?
?
quit
?
exit
?
bye
?
hello?
?
eat flaming death
?
^C
?
^C
?
^D
?


Note the consistent user interface and error reportage. Ed is generous enough to flag errors, yet prudent enough not to overwhelm the novice with verbosity.

“Ed is the standard text editor.”

Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!
When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a “viitor”. Not a “emacsitor”. Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

TEXT EDITOR.

When IBM, in its ever-present omnipotence, needed to base their “edlin” on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED “VISUAL” EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

?

Name: Anonymous 2010-04-20 21:09

>>20
Clearly you are a poseur. The world's last teletype ran out of ink in 2008.

Name: Anonymous 2010-04-21 7:45

>>20
????????????????????????????????????????????????????????????????????????????????????????????????????????????

Name: Anonymous 2010-04-21 7:47

>>22
9/10

Name: Anonymous 2011-04-15 0:27

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---

Ed, the greatest WYGIWYG editor of all.

[b]ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF [u]EDUCATED AND[/u] IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! [o][u]ED IS THE STANDARD TEXT EDITOR[/u][/o]! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!![/b]

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:34

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---

Name: Anonymous 2011-04-15 0:40

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

[b]ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:41

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:46

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! [/b]ED! ED IS THE STANDARD!![/b]!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:47

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:48

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:53

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY [/i]ED[/i] TO TEMPT THE [/u]FAITHLESS[/u]. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:54

you
you

Name: Anonymous 2011-04-15 0:54

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE [/u]FAITHLESS[/u]. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:55

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Name: Anonymous 2011-04-15 0:57

Ed, man! !man ed
ED(1)               Unix Programmer's Manual                ED(1)

NAME
     ed - text editor

SYNOPSIS
     ed [ - ] [ -x ] [ name ]
DESCRIPTION
     Ed is the standard text editor.

---


Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a "viitor". Not a "emacsitor". Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

When IBM, in its ever-present omnipotence, needed to base their "edlin" on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED "VISUAL" EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

Don't change these.
Name: Email:
Entire Thread Thread List