Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
aiutino regular expression in sed
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paolo Sala  
View profile   Translate to Translated (View Original)
 More options Nov 9, 5:50 am
Newsgroups: linux.debian.user.italian
From: Paolo Sala <piv...@riminilug.it>
Date: Mon, 09 Nov 2009 11:50:02 +0100
Local: Mon, Nov 9 2009 5:50 am
Subject: aiutino regular expression in sed
Ciao a tutti, come si fa a matchare tutto fino a che non contiene
opzionalmente una parola?

Ho dei file di testo tipo:
[...]
Sample Name:        909388-001 1° 1:10
[...]

oppure
[...]
Sample Name:        Std livello 3                  Injection
Volume:                                 25,0
[...]

oppure
[...]
Sample Name:         909436-002 1:2                 Injection
Volume:                              25,0
[...]

Io dovrei in questi file andare a prendere il sample name. Prima faccio
un grep Sample\ Name e poi pensavo di prendere il sample name con sed.
Mi piacerebbe dire qualcosa tipo:
prendi dopo Sample\ Name:[\ \t]* tutto fino a Injection oppure, se
Injection non c'è, fino alla fine della riga.

Spero di essermi spiegato.

Grazie mille

Piviul

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paolo Sala  
View profile   Translate to Translated (View Original)
 More options Nov 9, 6:40 am
Newsgroups: linux.debian.user.italian
From: Paolo Sala <piv...@riminilug.it>
Date: Mon, 09 Nov 2009 12:40:02 +0100
Local: Mon, Nov 9 2009 6:40 am
Subject: Re: aiutino regular expression in sed
Duffy DaC scrisse in data 09/11/2009 12:29:
> [Paolo Sala, lunedì 9 novembre 2009]

>> Mi piacerebbe dire qualcosa tipo:
>> prendi dopo Sample\ Name:[\ \t]* tutto fino a Injection oppure, se
>> Injection non c'è, fino alla fine della riga.

> Beh, potresti prima di tutto togliere "Injection", cosi poi ti basta
> gestire il caso in cui "Injection" non c'è..
> Ma mi pare troppo semplice, quindi forse non ho capito bene... :)

Invece hai capito benissimo!!! Lo sapevo che era semplice ma non mi
veniva in mente.

In ogni caso non è possibile fare il match di tutto fino a che non si
incontri la parola tizio oppure la parola caio? Questo non lo so proprio
fare.

Mille grazie.

Piviul

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Duffy DaC  
View profile   Translate to Translated (View Original)
 More options Nov 9, 6:40 am
Newsgroups: linux.debian.user.italian
From: Duffy DaC <duffy...@gmail.com>
Date: Mon, 09 Nov 2009 12:40:02 +0100
Local: Mon, Nov 9 2009 6:40 am
Subject: Re: aiutino regular expression in sed
[Paolo Sala, lunedì 9 novembre 2009]

> Mi piacerebbe dire qualcosa tipo:
> prendi dopo Sample\ Name:[\ \t]* tutto fino a Injection oppure, se
> Injection non c'è, fino alla fine della riga.

Beh, potresti prima di tutto togliere "Injection", cosi poi ti basta
gestire il caso in cui "Injection" non c'è..
Ma mi pare troppo semplice, quindi forse non ho capito bene... :)
--
DaC
44°59'N 7°27'E

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pietro Giorgianni  
View profile   Translate to Translated (View Original)
 More options Nov 9, 7:00 am
Newsgroups: linux.debian.user.italian
From: Pietro Giorgianni <giorg...@gmail.com>
Date: Mon, 09 Nov 2009 13:00:02 +0100
Local: Mon, Nov 9 2009 7:00 am
Subject: Re: aiutino regular expression in sed
Il 09 novembre 2009 11.43, Paolo Sala <piv...@riminilug.it> ha scritto:

> Io dovrei in questi file andare a prendere il sample name. Prima faccio
> un grep Sample\ Name e poi pensavo di prendere il sample name con sed.

A quanto pare, sed non supporta l'opzione nongreedy.

Una possibilità potrebbe essere cut, tipo:

grep ^Sample prova.txt | cut -b 15-50

Questo funziona se c'è una certa regolarità tra le colonne, ovvero se
non succede mai che Injection inizi prima di quando finisce l'ultimo
Sample Name.

Un'altra possibilità, se tra Sample Name: e il nome e poi tra il nome
e Injection ci sono almeno due spazi, è:

grep ^Samp prova.txt | sed "s/[ \t][ \t]\+/|/g" | gawk -F"|" '{print $2}'

pietro

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Duffy DaC  
View profile   Translate to Translated (View Original)
 More options Nov 9, 7:20 am
Newsgroups: linux.debian.user.italian
From: Duffy DaC <duffy...@gmail.com>
Date: Mon, 09 Nov 2009 13:20:03 +0100
Local: Mon, Nov 9 2009 7:20 am
Subject: Re: aiutino regular expression in sed
[Paolo Sala, lunedì 9 novembre 2009]

> In ogni caso non è possibile fare il match di tutto fino a che non
> si incontri la parola tizio oppure la parola caio? Questo non lo so
> proprio fare.

Una stringa di caratteri "comuni" dovrebbe matchare se stessa, quindi,
ammettendo che compaia in tutte le righe..

s/^Sample Name:[ \t]*\(.*\)[ \t]*Injection/&1/

dovrebbe *forse* (non l'ho provato) trasformarti la riga lasciando
solo ciò che ti interessa.

L'uso di \( \) e &1 penso tu lo possa approfondire nel man.

HTH,
--
DaC
44°59'N 7°27'E

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paolo Sala  
View profile   Translate to Translated (View Original)
 More options Nov 9, 8:20 am
Newsgroups: linux.debian.user.italian
From: Paolo Sala <piv...@riminilug.it>
Date: Mon, 09 Nov 2009 14:20:01 +0100
Local: Mon, Nov 9 2009 8:20 am
Subject: Re: aiutino regular expression in sed
Duffy DaC scrisse in data 09/11/2009 13:11:
> [Paolo Sala, lunedì 9 novembre 2009]

>> In ogni caso non è possibile fare il match di tutto fino a che non
>> si incontri la parola tizio oppure la parola caio? Questo non lo so
>> proprio fare.

> Una stringa di caratteri "comuni" dovrebbe matchare se stessa, quindi,
> ammettendo che compaia in tutte le righe..

> s/^Sample Name:[ \t]*\(.*\)[ \t]*Injection/&1/

volevi forse dire 's/^Sample Name:[ \t]*\(.*\)[ \t]*Injection/\1/'
altrimenti mi tira dietro anche Sample Name! Poi il problema è che
Injection dovrebbe essere opzionale e questo non so come fare a dirglielo...

Ciao e mille grazie ancora

Piviul

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paolo Sala  
View profile   Translate to Translated (View Original)
 More options Nov 9, 8:30 am
Newsgroups: linux.debian.user.italian
From: Paolo Sala <piv...@riminilug.it>
Date: Mon, 09 Nov 2009 14:30:02 +0100
Local: Mon, Nov 9 2009 8:30 am
Subject: Re: aiutino regular expression in sed
Pietro Giorgianni scrisse in data 09/11/2009 12:52:
> [...]
> Un'altra possibilità, se tra Sample Name: e il nome e poi tra il nome
> e Injection ci sono almeno due spazi, è:

era un'altra opzione che mi ero prefisso di vedere se riuscivo a
matchare ma non ce l'ho fatta...

> grep ^Samp prova.txt | sed "s/[ \t][ \t]\+/|/g" | gawk -F"|" '{print $2}'

Perfetto, non ci avevo pensato! al posto di gawk poi si potrebbe sempre
usare cut -d\| -f 2

Mille e mille grazie!!!

Piviul

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alfredo Finelli  
View profile   Translate to Translated (View Original)
 More options Nov 9, 9:20 am
Newsgroups: linux.debian.user.italian
From: Alfredo Finelli <0x4...@gmail.com>
Date: Mon, 09 Nov 2009 15:20:01 +0100
Local: Mon, Nov 9 2009 9:20 am
Subject: Re: aiutino regular expression in sed
* On Mon, 09 Nov 2009, at 11:43 +0100, Paolo Sala wrote:

[...]

Se ho capito bene ecco un esempio:

    $ cat file1.tmp
    Sample Name:        909388-001 1° 1:10

    Sample Name:        Std livello 3                  Injection
    Volume:                                 25,0

    Sample Name:         909436-002 1:2                 Injection
    Volume:                              25,0
    $ cat script.sed
    /^Sample Name:/ {
             s/[ \t]*Injection.*//
             s/^Sample Name:[ \t]*//
             p
    }
    $ sed -nf script.sed file1.tmp
    909388-001 1° 1:10
    Std livello 3
    909436-002 1:2
    $

Lo script sed seleziona solo le righe che servono, ne elimina la parte
finale se necessario, poi elimina la parte iniziale e poi stampa ciò che
rimane, cioè uno o più campi.  Sed è eseguito con l'opzione '-n' in modo
da non trovare sullo standard output tutte le altre righe.

Saluti,

alfredo

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scander  
View profile   Translate to Translated (View Original)
 More options Nov 9, 1:40 pm
Newsgroups: linux.debian.user.italian
From: Scander <c...@email.it>
Date: Mon, 09 Nov 2009 19:40:02 +0100
Local: Mon, Nov 9 2009 1:40 pm
Subject: Re: aiutino regular expression in sed
On Mon, 09 Nov 2009 11:43:24 +0100

Mah, se ho capito bene cosa intendi, secondo me si può fare tutto con
una sola riga di awk. Qualcosa tipo:

gawk  -F"Injection" '/Sample Name/ {split($1,a,"Sample Name:");print
a[2]}' nome_del_tuo_file

Non l'ho testato, magari fai una prova tu ;-)

Saluti
Scander

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Max  
View profile   Translate to Translated (View Original)
 More options Nov 10, 3:40 am
Newsgroups: linux.debian.user.italian
From: Max <max...@email.it>
Date: Tue, 10 Nov 2009 09:40:02 +0100
Local: Tues, Nov 10 2009 3:40 am
Subject: Re: aiutino regular expression in sed
Scander ha scritto:

> On Mon, 09 Nov 2009 11:43:24 +0100
> Paolo Sala <piv...@riminilug.it> wrote:

>> Ciao a tutti, come si fa a matchare tutto fino a che non contiene
>> opzionalmente una parola?
>> [...]
>> Sample Name:        Std livello 3                  Injection
>> Volume:                                 25,0
>> [...]

vuoi recuperare anche la riga con "Volume:"?
oppure solo quello che sta scritto dopo "Sample Name"?

Max

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paolo Sala  
View profile   Translate to Translated (View Original)
 More options Nov 10, 4:30 am
Newsgroups: linux.debian.user.italian
From: Paolo Sala <piv...@riminilug.it>
Date: Tue, 10 Nov 2009 10:30:02 +0100
Local: Tues, Nov 10 2009 4:30 am
Subject: Re: aiutino regular expression in sed
Max scrisse in data 10/11/2009 09:28:
> vuoi recuperare anche la riga con "Volume:"?
> oppure solo quello che sta scritto dopo "Sample Name"?

Solo Sample Name ma ho già fatto grazie ai vostri consigli.

Ancora mille e mille grazie

Piviul

--
Per REVOCARE l'iscrizione alla lista, inviare un email a
debian-italian-REQU...@lists.debian.org con oggetto "unsubscribe". Per
problemi inviare un email in INGLESE a listmas...@lists.debian.org

To UNSUBSCRIBE, email to debian-italian-REQU...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google