Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1

    Aiuto per espressione regolare

    Ho delle righe in un file di testo cosi'

    <a href="PAROLE A CASO ANCHE SPAZI E CARATTERI">

    Vorrei eliminare tutto quello che sta tra virgolette...

    ^(<a href=)[.]+(">)$ non funziona...
    Are you alive?
    No, but I was written with LOVE. A new scripting language.
    www.frequenze.it

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    1,798
    [sergio@localhost tmp]$ cat pagina.html
    <a href="PAROLE A CASO ANCHE SPAZI E CARATTERI">

    [sergio@localhost tmp]$ cat pagina.html | sed 's/".*"/""/'
    <a href="">

    Slack? Smack!

  3. #3
    Utente di HTML.it L'avatar di Sym81
    Registrato dal
    Jan 2002
    Messaggi
    114
    Magari non usando espressioni regolari avevi già risolto, in ogni caso:

    TEST="<a href=\"PAROLE A CASO ANCHE SPAZI E CARATTERI\">"
    PRIMA=`echo $TEST | cut -d'"' -f1`
    DOPO=`echo $TEST | cut -d'"' -f3`
    echo "$PRIMA\"\"$DOPO"
    Ciao
    "Dream on
    Do you believe...all the things that you are seeing are true?
    The Start's where the End's leading you
    Do you believe...all's as twisted as one would perceive?
    Seek the Answer and soon you'll believe"

  4. #4
    Utente di HTML.it L'avatar di Sym81
    Registrato dal
    Jan 2002
    Messaggi
    114
    Originariamente inviato da Sergio Pedone
    [sergio@localhost tmp]$ cat pagina.html
    <a href="PAROLE A CASO ANCHE SPAZI E CARATTERI">

    [sergio@localhost tmp]$ cat pagina.html | sed 's/".*"/""/'
    <a href="">

    Ah ecco a cosa serve sed!
    "Dream on
    Do you believe...all the things that you are seeing are true?
    The Start's where the End's leading you
    Do you believe...all's as twisted as one would perceive?
    Seek the Answer and soon you'll believe"

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    1,798
    Originariamente inviato da Sym81
    Magari non usando espressioni regolari avevi già risolto, in ogni caso:



    Ciao
    Ciao Sym81!
    Il tuo esempio non fa una grinza quando si tratta di una sola
    riga da elaborare. Bastano 2 righe e va in crisi:

    codice:
    [sergio@localhost tmp]$ cat pagina.html
    <a href="PAROLE A CASO ANCHE SPAZI E CARATTERI">
    <a href="PAROLE A CASO ANCHE SPAZI E CARATTERI">
    [sergio@localhost tmp]$ prima=`cat pagina.html | cut -d '"' -f1`
    [sergio@localhost tmp]$ dopo=`cat pagina.html | cut -d '"' -f3`
    [sergio@localhost tmp]$ echo "$prima\"\"$dopo"
    <a href=
    <a href="">
    >
    La soluzione con sed è più indicata, secondo me.
    codice:
    [sergio@localhost tmp]$ cat pagina.html | sed 's/".*"/""/'
    <a href="">
    <a href="">
    [sergio@localhost tmp]$
    Slack? Smack!

  6. #6
    Originariamente inviato da Sergio Pedone
    [sergio@localhost tmp]$ cat pagina.html
    <a href="PAROLE A CASO ANCHE SPAZI E CARATTERI">

    [sergio@localhost tmp]$ cat pagina.html | sed 's/".*"/""/'
    <a href="">

    Sei un genio!

    Senti ma posso usare le regex con SED??
    Are you alive?
    No, but I was written with LOVE. A new scripting language.
    www.frequenze.it

  7. #7
    Utente di HTML.it L'avatar di Sym81
    Registrato dal
    Jan 2002
    Messaggi
    114
    Hai ragione, il tutto sarebbe da mettere in un for che gestisce riga per riga ma non ne vale assolutamente la pena. Sed gestisce tutto molto più semplicemente, peccato non l'abbia ancora studiato Ciao Sergio
    "Dream on
    Do you believe...all the things that you are seeing are true?
    The Start's where the End's leading you
    Do you believe...all's as twisted as one would perceive?
    Seek the Answer and soon you'll believe"

  8. #8
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    1,798
    Originariamente inviato da Mutato
    Senti ma posso usare le regex con SED??
    Certamente.
    Dai una lettura qui:
    http://a2.swlibero.org/sed_introduzione.html

    Ciao a tutti.
    Slack? Smack!

  9. #9
    Utente di HTML.it L'avatar di Sym81
    Registrato dal
    Jan 2002
    Messaggi
    114
    Giusto per sfizio:

    cat pagina.html | awk 'BEGIN { FS="\"" } { print $1"\"\""$3 }'
    "Dream on
    Do you believe...all the things that you are seeing are true?
    The Start's where the End's leading you
    Do you believe...all's as twisted as one would perceive?
    Seek the Answer and soon you'll believe"

  10. #10
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    1,798
    Originariamente inviato da Sym81
    Giusto per sfizio:
    Ecco, mi hai subito scoperto...
    non conosco awk!
    Slack? Smack!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.