PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > how to strip off a field
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

how to strip off a field

Réponse
 
LinkBack Outils de la discussion
Vieux 07/11/2006, 21h34   #1
rogv24@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how to strip off a field


I have a bunch of email addresses

abc@yahoo.com
defgh@google.com

I just want to keep the domains and strip of the name:
like: yahoo.com
google.com

  Réponse avec citation
Vieux 07/11/2006, 21h39   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to strip off a field

2006-11-7, 13:34(-08), rogv24@yahoo.com:
>
> I have a bunch of email addresses
>
> abc@yahoo.com
> defgh@google.com
>
> I just want to keep the domains and strip of the name:
> like: yahoo.com
> google.com


cut -d@ -f2- << EOF
abc@yahoo.com
defgh@google.com
EOF

--
Stéphane
  Réponse avec citation
Vieux 07/11/2006, 21h51   #3
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to strip off a field

On 2006-11-07, rogv24@yahoo.com wrote:
>
> I have a bunch of email addresses
>
> abc@yahoo.com
> defgh@google.com
>
> I just want to keep the domains and strip of the name:
> like: yahoo.com
> google.com


How do you "have" them?

If they are in variables, use parameter expansion:

email=abc@yahoo.com
domain=${email#*@}


If they are in a file, use cut:

cut -d@ -f2 FILE

Or, if you need to manipulate the domains after extracting them:

while IFS=@ read a domain
do
## DO something with $domain here
done < FILE

Or:

awk -F@ '{ domain=$2
# do something with domain here
}' FILE


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 07/11/2006, 21h53   #4
rogv24@yahoo.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to strip off a field

Thank you


Stephane CHAZELAS wrote:
> 2006-11-7, 13:34(-08), rogv24@yahoo.com:
> >
> > I have a bunch of email addresses
> >
> > abc@yahoo.com
> > defgh@google.com
> >
> > I just want to keep the domains and strip of the name:
> > like: yahoo.com
> > google.com

>
> cut -d@ -f2- << EOF
> abc@yahoo.com
> defgh@google.com
> EOF
>
> --
> Stéphane


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h03.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12098 seconds with 12 queries