2009-11-09 10 views

Répondre

0
grep -o "PART I WANT TO EXTRACT" foo 

Edit: "PARTIE JE VEUX Extract" peut être une expression rationnelle, à savoir :

grep -o http://[a-z/.]* foo 
+0

J'utilise: > 'grep -o 'http: // [az/.A-Z0-9] * " > \ [link \]'' mais il me donne: > 'http: // img18.imageshack.us/img18/8079/69903601.jpg " > [link] ' Je ne veux pas les choses à la fin. – Josh

+0

Eh bien, vous pourriez grep à trouver, puis utilisez grep -o pour obtenir l'expression:> grep 'http: // [a-z/.A-Z0-9] * " > \ [link \]' | grep -o 'http: // [a-z/.A-Z0-9] * – ctd

0
expr "$string" : 'href="\(.*\)">\[link\]' 
2

utilisation awk

$ echo "href="PART I WANT TO EXTRACT">[link]" | awk -F""" '{print $2}' 
PART I WANT TO EXTRACT 

Ou shell en utilisant lui-même

$ a="href="PART I WANT TO EXTRACT">[link]" 
$ a=${a//"/} 
$ echo ${a/&*/} 
PART I WANT TO EXTRACT 
2

Voici une autre façon Bash:

$ string="href="PART I WANT TO EXTRACT">[link]" 
$ entity=""" 
$ string=${string#*${entity}*} 
$ string=${string%*${entity}*} 
$ echo $string 
PART I WANT TO EXTRACT 

Ceci illustre deux caractéristiques: Supprimer le préfixe correspondant/modèle de suffixe et la utilisation d'une variable pour contenir le motif (vous pouvez utiliser un littéral à la place).

Questions connexes