Unix/Linux Forum: Nawk / AWK - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Nawk / AWK Illegal statemnet Rate Topic: -----

#1 User is offline   rockstar Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 9
  • Joined: 02-October 08

Posted 02 October 2008 - 01:37 AM

Hi all,

Could anyone tell me what's wrong with my script below?

echo "please enter name"
read name

echo "Please enter new new group id"
echo answer

nawk -F: -v user="$name" '$1 == user{print $1 ":" $4="$answer"}' $PASSWD

I tried to change a group id of specific user

please help :(
0

#2 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 03 October 2008 - 05:38 AM

Hey There,

The $4=$answer probably isnt' resolving in awk,

you could add an extra -v

-v answer=$answer

preceding it or use double quotes around your awk statement,a lthough that will probably cause issues with the awk variables, so:

 nawk -F: -v answer=$answer -v user="$name" '$1 == user{print $1 ":" $4=answer}' $PASSWD


Might work.

best wishes,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

#3 User is offline   rockstar Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 9
  • Joined: 02-October 08

Posted 08 October 2008 - 06:10 AM

it doesn not

complaining as illegal statement
0

#4 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 09 October 2008 - 04:32 AM

Hey there,

My fault - used awk.

It won't work with nawk either, but this will - same thing - different order:

nawk -F: -v answer=$answer -v user="$name" '{ if ( $1 == user ) print $1 ":" answer }' $PASSWD


Best wishes,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

#5 User is offline   rockstar Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 9
  • Joined: 02-October 08

Posted 09 October 2008 - 09:10 AM

Hi eggi,

It works..

But my question is how do i know if answer is replacing $4 field?

When i run the script as you mentioned, the output is blah:XXX
0

#6 User is offline   rockstar Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 9
  • Joined: 02-October 08

Posted 09 October 2008 - 09:24 AM

Hi Eggi,

don't worry..

I managed to get it on the right field by using:


nawk -F: -v answer=$answer -v user="$name" '{ if ( $1 == user ) print $1 ":" $2 ":" $3 ":" answer }' $PASSWD
0

#7 User is offline   rockstar Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 9
  • Joined: 02-October 08

Posted 09 October 2008 - 09:24 AM

Thank you for helping eggie
0

#8 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 10 October 2008 - 04:08 AM

Glad I could :)

Take care,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Cambridge Plus :: Cambridgeshire Steam Rally :: USB Temperature Monitor :: Wellworthy Piston Rings
Unix Man Pages / Linux Man Pages :: HiFi Forum :: A14 Comments :: UNIX/Linux Forum Archives