[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: altro aiuto con sed/awk (3)



per esempio, ho fatto alcune prove con sed ma non ottengo i risultati
che vorrei:

$ echo "[img]http://faidateoffgrid.altervista.org/forum/attachment/1372260472.jpg[/img]
[img]Questo non deve cambiare[/img]" | sed '/faidateoffgrid/  {
s|\(\[img\]http://faidateoffgrid.altervista.org/forum/attachment\)|\[img-local\]attachment|g
; s/\[\/img\]/\[\/img-local\]/g }'

risultato:
[img-local]attachment/1372260472.jpg[/img-local] [img]Questo non deve
cambiare[/img-local]

mi cambia entrambi i tag finali.
come faccio a spiegare a sed, che deve cambiare i tag finali solo per
quei pattern che rispettano determinate condizioni?

ciao
MAX

2013/7/15, MaX <maxlinux2000@gmail.com>:
> ciao a tuttim
>
> come sempre arrivo qui per chiedere aiuto con sed
>
> questa volta devo sostituire una serie di tag bbcode con altri, ma
> solo con le immangini che sono in un determinato path
>
> immaginiamo di avere un file contenente:
> ---------------------------------------------------------------------------------------------------------------------
>
> [img]http://faidateoffgrid.altervista.org/forum/attachment/1373389057.jpg[/img]
> questa è l'immagine 1
> http://energiaalternativa.forumcommunity.net/?t=54611292&p=382785730
> questa è l' URL 1
> [img]http://img.forumfree.net/html/emoticons/biggrin.gif[/img]  questo
> è lo smile 1
> [img]http://faidateoffgrid.altervista.org/forum/attachment/1373389058.jpg[/img]
>  questa è l'immagine 2
>
> ----------------------------------------------------------------------------------------------------------------------
>
> dopo un $ cat file | sed "qualchecosa"
>
> dovrebbe venire fuori cosí:
>
> ---------------------------------------------------------------------------------------------------------------------
>
> [img-local]attachment/1373389057.jpg[/img-local] questa è l'immagine 1
> http://energiaalternativa.forumcommunity.net/?t=54611292&p=382785730 URL 1
> [img]http://img.forumfree.net/html/emoticons/biggrin.gif[/img] questo
> è lo smile 1
> [img-local]forum/attachment/1373389058.jpg[/img-local] questa è l'immagine
> 2
>
> ----------------------------------------------------------------------------------------------------------------------
>
>
> praticamente il sed dovebbe cambiare solo i pattern conteneti
>
> [img]http://faidateoffgrid.altervista.org/forum/attachment
>
> in
>
> [img-local]attachment
>
> e fin li è facile
>
> ma poi SOLO in quelle stringhe deve cambiare anche il [/img] in
> [/img-local], lasciando invariato tutto il resto di frasi, url e tag
>
> naturalmente possono esserci più url con tag da cambiare per linea
> mischiate con altre che non vanno modificate....
>
> qualche idea?
>
> grazie in anticipo
>
> --
> ciao,
> MaX
>


-- 
ciao,
MaX


Reply to: