" quello che voglio è di due variabili DB1 \u003d dati" /> Estrarre stringa tra <> - La UNIX e Linux Forum
The UNIX and Linux Forums  
Ciao e benvenuto da parte degli Stati Uniti al UNIX e Linux Forum! Grazie per la visita ed unirsi alla nostra Comunità Globale.

Go Back   UNIX e Linux Forum > Inizio Forum > Shell scripting e di programmazione
.
google unix.com



Shell scripting e di programmazione Pubblica domande su KSH, CSH, SH, Bash, Perl, PHP, sed, awk e da altri script di shell e linguaggi di scripting shell qui.

Più di UNIX e Linux Forum Argomenti potreste trovare utili
Filo Thread Starter Forum Risposte Ultimo Post
Come estrarre stringa? namrata5 Di programmazione ad alto livello 2 10-24-2007 04:17 AM
Estrarre cifre a fine stringa offirc Shell scripting e di programmazione 6 11-20-2006 11:57 AM
Estrarre Stringa sehgalniraj UNIX for Dummies Domande & Risposte 1 09-25-2006 01:35 PM
Estrarre Stringa bestbuyernc Shell scripting e di programmazione 5 11-14-2005 03:42 PM
Come per estrarre una porzione di una stringa da tutta la stringa ds_sastry UNIX for Dummies Domande & Risposte 2 09-29-2001 11:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Cerca in questo Thread Rate Thread Modalità di visualizzazione
  #1 (permalink)  
Old 11-20-2007
rakeshou rakeshou is offline
Utente Registrato
  
 

Join Date: May 2007
Interventi: 75
Wink Estrarre stringa tra <>

salve,

Vorrei un modo semplice per estrarre stringa tra due parentesi angolari <>

il testo si presenta come

echo "# # # Utilizzo: $ 0 <database1> <database2>"

quello che voglio è di due variabili database1 \u003d DB1 e DB2 \u003d database2

Che cosa sto facendo per me guarda maldestra

Codice:
DB1=`echo $line | sed 's/"//g' | sed 's/>//g' | awk -F"<" '{print $2}'`
DB2=`echo $line | sed 's/"//g' | sed 's/>//g' | awk -F"<" '{print $3}'`
grazie in anticipo
  #2 (permalink)  
Old 11-20-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Iscriviti Data: gennaio 2007
Ubicazione: Варна, България / Milano, Italia
Messaggi: 2.875
Con bash/ksh93:

Codice:
line='###Usage: $0 <database1> <database2>' line=(${line//[<>]})
db1="${line[2]}" db2="${line[3]}"
Con zsh:

Codice:
line=(${=line//[<>]})
db1="${line[3]}" db2="${line[4]}"
Oppure:

Codice:
db1="${${(m)line%*> <*}#*<}"
db2="${${(m)line#*> <}%?}"
  #3 (permalink)  
Old 11-20-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderatore
  
 

Iscriviti Data: febbraio 2005
Località: Boston, MA
Messaggi: 5.122
Codice:
echo "${line}" | nawk -F '(<|>)' '{ printf("DB1=%s;DB2=%s\n", $2, $4)}'
  #4 (permalink)  
Old 11-20-2007
rakeshou rakeshou is offline
Utente Registrato
  
 

Join Date: May 2007
Interventi: 75
Thats pulito

ci sono altri modi per farlo?

Grazie
  #5 (permalink)  
Old 11-20-2007
Franklin52 Franklin52 is online now Forum Staff  
Moderatore
  
 

Iscriviti Data: febbraio 2007
Messaggi: 4.309
Codice:
DB1=`echo $line | sed 's/.*<\(.*\)> <.*/\1/'`

DB2=`echo $line | sed 's/.*> <\(.*\)>"/\1/'`
Saluti
  #6 (permalink)  
Old 11-20-2007
rakeshou rakeshou is offline
Utente Registrato
  
 

Join Date: May 2007
Interventi: 75
didnt molto lavoro

Citazione:
Originalmente inviato da Franklin52 View Post
Codice:
DB1=`echo $line | sed 's/.*<\(.*\)> <.*/\1/'`

DB2=`echo $line | sed 's/.*> <\(.*\)>"/\1/'`
Saluti
bash-3,00 $ line \u003d'### Utilizzo: $ 0 <database1> <database2> '
bash-3,00 $ DB1 \u003d `echo $ line | sed 's / .* <\ (.* \)> <.* / \ 1 /' `
bash-3,00 $
bash-3,00 $ DB2 \u003d `echo $ line | sed 's / .*> <\ (.* \)> "/ \ 1 /'`
bash-3,00 $ echo $ DB1
database1
bash-3,00 $ echo $ DB2
# # # Utilizzo: $ 0 <database1> <database2>
bash-3,00 $
  #7 (permalink)  
Old 11-20-2007
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Iscriviti Data: luglio 2001
Località: Portland, OR, Stati Uniti d'America
Interventi: 1.584
Ahh crikey - Ho appena notato radoulov post. Buona chiamata.

Ultimo a cura di LivinFree; al 11/20/2007 01:58 PM..
Closed Thread

Segnalibri

Thread Tools Cerca in questo Thread
Cerca in questo Thread:

Ricerca Avanzata
Modalità di visualizzazione Vota questo thread
Vota questo thread:

Distacco regolamento
Tu non può post nuovo thread
Tu non può inviare una risposta
Tu non può postare allegati
Tu non può modificare i tuoi post

BB codice è Su
Smilies sono Su
[IMG] codice Su
Codice HTML è Chiuso
Trackbacks sono Su
Pingbacks sono Su
Refbacks sono Su




Tutti gli orari sono GMT -4. La data di oggi è 03:27 PM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Traduzioni Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX e Linux Forum Content Copyright © 1993-2009. Tutti i diritti Reserved.Ad di gestione da RedTyger

Contenuti pertinenti URL da vBSEO 3.2.0