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 > awk -v option quit working.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

awk -v option quit working.

Réponse
 
LinkBack Outils de la discussion
Vieux 02/11/2006, 14h01   #1
Noatec
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut awk -v option quit working.

Hey all,
I'm looking for some with awk.
Our Midrange (unix) team just upgraded our lpar from aix 5.1 to 5.2ML6
Since the upgrade my awk -v option has stopped working.

The syntax below will find the literal value "M" in the ps list, not
the contents of variable $CS.

for CS in R1 R3 A1 A3
do
CSPID=`ps -ef|awk -v M=$CS '/M/ && /exec/ && !/awk/ {print $2}'`

Have I been getting away with incorrect syntax all along or is there
really a bug?

Any insight would be ful.

Thanks,
Roger

  Réponse avec citation
Vieux 02/11/2006, 14h15   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk -v option quit working.

Noatec wrote:
> Hey all,
> I'm looking for some with awk.
> Our Midrange (unix) team just upgraded our lpar from aix 5.1 to 5.2ML6
> Since the upgrade my awk -v option has stopped working.
>
> The syntax below will find the literal value "M" in the ps list, not
> the contents of variable $CS.
>
> for CS in R1 R3 A1 A3
> do
> CSPID=`ps -ef|awk -v M=$CS '/M/ && /exec/ && !/awk/ {print $2}'`
>
> Have I been getting away with incorrect syntax all along or is there
> really a bug?


Your syntax is wrong. The above would search for the character "M" not
the value of the variable "M". What you want is:

awk -v M="$CS" '($0 ~ M) && /exec/ && !/awk/ {print $2}'

Ed.
  Réponse avec citation
Vieux 02/11/2006, 14h33   #3
Daniel Rock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk -v option quit working.

Noatec <Noatec@gmail.com> wrote:
> Hey all,
> I'm looking for some with awk.
> Our Midrange (unix) team just upgraded our lpar from aix 5.1 to 5.2ML6
> Since the upgrade my awk -v option has stopped working.
>
> The syntax below will find the literal value "M" in the ps list, not
> the contents of variable $CS.
>
> for CS in R1 R3 A1 A3
> do
> CSPID=`ps -ef|awk -v M=$CS '/M/ && /exec/ && !/awk/ {print $2}'`
>
> Have I been getting away with incorrect syntax all along or is there
> really a bug?


Most likely.

The right syntax would more look like:

$(ps -ef | awk -v M=$CS 'match($0, X) && /exe/ && !/awk/ { print $2}')


--
Daniel
  Réponse avec citation
Vieux 02/11/2006, 16h02   #4
Noatec
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: awk -v option quit working.

Both examples worked perfectly !!
Thanks Guys.

I know it doesn't make it right, but my syntax did work in AIX 5.1

  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 02h44.


É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,08919 seconds with 12 queries