Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[sed] selezionare una word [[risolto]]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano
View previous topic :: View next topic  
Author Message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4815
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sun Jan 08, 2006 11:00 am    Post subject: [sed] selezionare una word [[risolto]] Reply with quote

Nel tentativo di creare un initrd vecchia maniera, mi sono imbattuto nel problema seguente.
Per la verità, non so fino a che punto la questione si possa considerare IT, ma lascio che siano i moderatori a intervenire come pensano.

Ora. Voglio estrarre la real_root dalla seguente command line:
Code:

s939 ~ # cat cmdline
kernel /kernel-2.6.9-gentoo-r9 udev dolvm2 root=/dev/ram0 real_root=/dev/vg/root init=/linvxrc video=vesafb:ywrap,mtrr,1024x768-16@85 splash=silent,theme:emergence

Preliminarmente, ho bisogno di selezionare la stringa "real_root=/dev/vg/root". Per intanto, ho provato a sostituirla con il tag <match> per vedere come funziona:
Code:

s939 ~ # sed -e 's£rea[^[:space:]]*[:space:]£<match>£' cmdline
kernel /kernel-2.6.9-gentoo-r9 udev dolvm2 root=/dev/ram0 <match>v/vg/root init=/linvxrc video=vesafb:ywrap,mtrr,1024x768-16@85 splash=silent,theme:emergence


    1: sto usando la sintassi s£££ al posto di s/// per evitare di trattare i backslash come caratteri speciali.
    2: ls sequenza 'rea[^[:space:]]*[:space:]' dovrebbe indicare un testo che incomincia con rea, che è seguito da un numero indeterminato (*) di caratteri non (^)di spaziatura e che termina con un carattere di spaziatura. Dunque dovrebbe identificare proprio la stringa 'real_root=/dev/vg/root'.
    3: a quanto pare, la stringa match copre soltanto una frazione del testo atteso, perché non include i caratteri 'v/vg/root' che non contengono alcun elemento di spaziatura.
    4: provando a sostituire 'rea' con 'ker' o con 'vid' ottengo nuovamente effetti scorretti (a mio parere), mentre se uso 'ini', la sostituzione risulta misteriosamente esatta:
    Code:

    s939 ~ # sed -e 's£ini[^[:space:]]*[:space:]£<match>£' cmdline
    kernel /kernel-2.6.9-gentoo-r9 udev dolvm2 root=/dev/ram0 real_root=/dev/vg/root <match> video=vesafb:ywrap,mtrr,1024x768-16@85 splash=silent,theme:emergence


Nota: se avete dei workaround, proponeteli pure. Io ne ho trovato uno funzionante:
Code:

s939 ~ # sed -e 's/[[:space:]]/\n/g' cmdline |sed -n /real/p
real_root=/dev/vg/root

ma il mio interesse principale sarebbe proprio di capire cosa c'è nella tecnica che sto provando ad utilizzare che non vada.
_________________
vu vu vu
gentù
mi piaci tu


Last edited by cloc3 on Mon Jan 09, 2006 12:30 am; edited 2 times in total
Back to top
View user's profile Send private message
makoomba
Bodhisattva
Bodhisattva


Joined: 03 Jun 2004
Posts: 1856

PostPosted: Sun Jan 08, 2006 2:40 pm    Post subject: Reply with quote

Code:
sed -e 's|rea[^ ]*[ ]|<match>|' cmdline
kernel /kernel-2.6.9-gentoo-r9 udev dolvm2 root=/dev/ram0 <match>video=vesafb:ywrap,mtrr,1024x768-16@85 splash=silent,theme:emergence

_________________
When all else fails, read the instructions.
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4815
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sun Jan 08, 2006 4:12 pm    Post subject: Reply with quote

makoomba wrote:
Code:
sed -e 's|rea[^ ]*[ ]|<match>|' cmdline
kernel /kernel-2.6.9-gentoo-r9 udev dolvm2 root=/dev/ram0 <match>video=vesafb:ywrap,mtrr,1024x768-16@85 splash=silent,theme:emergence

Grazie. Adesso ho capito:
Code:

s939 ~ # sed -e 's|rea[^[:space:]]*[ ]|<match> |' cmdline
kernel /kernel-2.6.9-gentoo-r9 udev dolvm2 root=/dev/ram0 <match> init=/linuxrc video=vesafb:ywrap,mtrr,1024x768-16@85 splash=silent,theme:emergence

In pratica, il secondo spazio deve essere identificato come singolo carattere e non come classe, altrimenti va in palla.
Per il primo, invece, comprende entrambe le sintassi.

Inoltre, ho scoperto uno strano fenomeno. Guarda adesso:
Code:

s939 ~ # sed -e 's£rea[^[:space:]]*[:space:]£<match>£' cmdline
sed: -e expression #1, char 39: unknown option to `s'

Differenza? Prima lavoravo in ssh da una macchina remota, e il simbolo di £ veniva accettato. Adesso sono in locale.
Devo avere qualche incongruenza nella definizione dei miei set di caratteri.
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
makoomba
Bodhisattva
Bodhisattva


Joined: 03 Jun 2004
Posts: 1856

PostPosted: Sun Jan 08, 2006 4:17 pm    Post subject: Reply with quote

sei sicuro che sed riconosca le classi ?
Code:
mail ~ # echo "ciao ciao" | sed -e 's| |/|g'
ciao/ciao
mail ~ # echo "ciao ciao" | sed -e 's|[:space:]|/|g'
/i/o /i/o
mail ~ #

imho, le vede come semplici sequenze di catteri
_________________
When all else fails, read the instructions.
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4815
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sun Jan 08, 2006 5:04 pm    Post subject: Reply with quote

makoomba wrote:
sei sicuro che sed riconosca le classi ?

Sicuro niente. Sto facendo le prime prove e il concetto di classe non mi è chiaro del tutto.
Su molti howto ho trovato esempi di uso delle classi e mi pareva che si dovessero utilizzare nel caso mio.
Invece, pare che ci pigliano un 50% (come il Beethoven dei fichi di Guccini). Forse, un esperto di sed saprà anche spiegare il perché.
_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
cloc3
Advocate
Advocate


Joined: 13 Jan 2004
Posts: 4815
Location: http://www.gentoo-users.org/user/cloc3/

PostPosted: Sun Jan 08, 2006 6:32 pm    Post subject: Reply with quote

makoomba wrote:
sei sicuro che sed riconosca le classi ?
Code:
mail ~ # echo "ciao ciao" | sed -e 's| |/|g'
ciao/ciao
mail ~ # echo "ciao ciao" | sed -e 's|[:space:]|/|g'
/i/o /i/o
mail ~ #

imho, le vede come semplici sequenze di catteri

Scusa. La questione è risolta, ma io ci sto ancora filando...
Nel tuo esempio:
Code:

cloc3@s939 ~ $ echo "ciao ciao" | sed -e 's|[[:space:]]|/|g'
ciao/ciao

_________________
vu vu vu
gentù
mi piaci tu
Back to top
View user's profile Send private message
makoomba
Bodhisattva
Bodhisattva


Joined: 03 Jun 2004
Posts: 1856

PostPosted: Sun Jan 08, 2006 6:43 pm    Post subject: Reply with quote

ah, ok
le vuole doppie
Code:
 sed -e 's|rea[^[:space:]]*[[:space:]]|<match>|' cmdline

così funge anche questa
_________________
When all else fails, read the instructions.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) Forum di discussione italiano All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum