zamena vice radek pomoci sed?

Pavel Lisy pali na tmapy.cz
Úterý Září 24 14:49:43 CEST 2002


On Út, 2002-09-24 at 13:21, Matthes wrote:
> Zdravim,
> 
> tak uz zase zapasim se sed-em :)
> 
> pri upravach jednoho rozsahlejsiho webu jsem chtel pomoci sed-u zamenit 
> viceradkovy kus kodu ve strankach jinou porci kodu, ale at delam co 
> delam, nedokazu mu vnutit, aby zpracoval pattern, ktery jde pres vice 
> radek.
> prikaz sed 's/<zacatek_stareho_kodu>.*<\/konec_stareho_kodu>/<novy_kod>/g' 
> nereaguje, kdyz pouziju "\n" tam, kde se lame radek, kasle na to 
> stejne...
toto by melo dle dokumentace fungovat:
`s/REGEXP/REPLACEMENT/FLAGS'
     (The `/' characters may be uniformly replaced by any other single
     character within any given `s' command.)

     The `/' character (or whatever other character is used in its
     stead) can appear in the REGEXP or REPLACEMENT only if it is
     preceded by a `\' character.  Also newlines may appear in the
     REGEXP using the two character sequence `\n'.

     The REPLACEMENT can contain `\N' (N being a number from 1 to 9,
     inclusive) references, which refer to the portion of the match
     which is contained between the Nth `\(' and its matching `\)'.
     Also, the REPLACEMENT can contain unescaped `&' characters which
     will reference the whole matched portion of the pattern space.  To
     include a literal `\', `&', or newline in the final replacement,
     be sure to precede the desired `\', `&', or newline in the
     REPLACEMENT with a `\'.

urcite to ale funguje v perlu

zkuste toto, ale konec radku se myslim oznacuje $ 
perl -p -e "s/../../g"


> Dalsi vec je, ze pokud prikaz s/../../g neuzavru do apostrofu, sed hlasi, 
> ze neni ukoncen prikaz. Ale mezi apostrofy se zase neprovede rozvinuti 
> promennych... kdyz to dam mezi uvozovky, nefunguje to taky.
> 
> Jak mu mam tyhle veci vysvetlit?
"s/../../g" musi fungovat, pouze muze byt problem, ze se vam promenna
rozvine do textu s / a najednou jich tam mate moc. 
Bez apostrofu zase * interpretuje shell, muselo by tam byt \*


Pavel
-- 
Ing. Pavel Lisy <pali na tmapy.cz>
T-MAPY spol. s r.o., http://www.tmapy.cz
Nezvalova 850, Hradec Kralove, 50003
tel: +420-49-5513335 fax: +420-49-5513371

O mapach vime vse: http://www.tmapserver.cz



Další informace o konferenci Linux