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 > cat and grep redirection
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

cat and grep redirection

Réponse
 
LinkBack Outils de la discussion
Vieux 10/12/2006, 07h18   #1
cconnell_1@lycos.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut cat and grep redirection

Hi,
I am trying to do something in my script as follows, it sends the
following output to the file hosts as follows:

mgt=b01
cat >> ./hosts <<EOF
#
#
10.32.25.34 b01
10.32.25.35 b02
10.32.25.36 b03
EOF

I want to cat the output to the hosts file but 'exclude' the line if
the line has the value of the 'mgt' variable so in the above example I
would get in the hosts file.

#
#
10.32.25.35 b02
10.32.25.36 b03


I have tried using cat with grep -v "$mgt" with no luck. I think Im
redirecting something wrong. Thanks for any .

  Réponse avec citation
Vieux 10/12/2006, 07h34   #2
Klaus Alexander Seistrup
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: cat and grep redirection

cconnell_1@lycos.com wrote:

> mgt=b01
> cat >> ./hosts <<EOF
> #
> #
> 10.32.25.34 b01
> 10.32.25.35 b02
> 10.32.25.36 b03
> EOF
>
> [...]
>
> I have tried using cat with grep -v "$mgt" with no luck.


This works for me:

#v+

mgt=b01
grep -v "$mgt" <<EOF >>./hosts
#
#
10.32.25.34 b01
10.32.25.35 b02
10.32.25.36 b03
EOF

#v-

Cheers,

--
Klaus Alexander Seistrup
http://klaus.seistrup.dk/
  Réponse avec citation
Vieux 10/12/2006, 07h42   #3
RolandRB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: cat and grep redirection


cconnell_1@lycos.com wrote:
> Hi,
> I am trying to do something in my script as follows, it sends the
> following output to the file hosts as follows:
>
> mgt=b01
> cat >> ./hosts <<EOF
> #
> #
> 10.32.25.34 b01
> 10.32.25.35 b02
> 10.32.25.36 b03
> EOF
>
> I want to cat the output to the hosts file but 'exclude' the line if
> the line has the value of the 'mgt' variable so in the above example I
> would get in the hosts file.
>
> #
> #
> 10.32.25.35 b02
> 10.32.25.36 b03
>
>
> I have tried using cat with grep -v "$mgt" with no luck. I think Im
> redirecting something wrong. Thanks for any .


It works for me:

mgt=b01
cat << EOF | grep -v "$mgt" > roland.txt
#
#
10.32.25.34 b01
10.32.25.35 b02
10.32.25.36 b03
EOF

cat roland.txt

  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 19h25.


É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,09266 seconds with 11 queries