perl one liner

I need to delted an "additional root user" out of /etc/passwd and /etc/shadow.

I would prefer just to lock the account but that is another issue, I have to delete.

How do I delete the line that has user name  Root_n_tooten

Perl one liners work great for me

I assume it will look something like

perl -i  -pe 's/^(root-n-tooten)/#$1/' file
but it would not comment out , it would remove the line






TIMFOX123Asked:
Who is Participating?
 
farzanjConnect With a Mentor Commented:
Oops, you have older version of sed.

Try this instead:

perl -ni -e 'print unless /^root-n-tooten/' /etc/passwd
perl -ni -e 'print unless /^root-n-tooten/' /etc/shadow

Open in new window

0
 
farzanjCommented:
It works for me.
0
 
farzanjCommented:
So do you want to comment it or delete the line?  It is commenting out correctly.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
arnoldCommented:
userdell root-n-tooten

0
 
TIMFOX123Author Commented:
I need to delete the line

userdell has taken both users away and the people that own the box are not happy when the root account gets deleted.  

thank you
0
 
farzanjCommented:
Try this,
sed -i /root-n-tooten/d /etc/passwd
 sed -i /root-n-tooten/d /etc/shadow

Open in new window

0
 
farzanjCommented:
Or if you want to make sure that it is in the beginning of the line
sed -i /^root-n-tooten/d /etc/passwd
sed -i /^root-n-tooten/d /etc/shadow

Open in new window

0
 
arnoldCommented:
perhaps the userdell 'root\-n\-tooten' is a better approach to make sure that the - is not treated as an argument to userdel.

You only need to remove the entry from /etc/passwd and then run pwconv which will synchronize the /etc/shadow entries based on the entries in /etc/passwd/

farzani's sed works.
0
 
TIMFOX123Author Commented:
what do I do about this when I try to run that :

$ sed: illegal option -- i

this has to work in aix, solaris and linux

0
 
TIMFOX123Author Commented:
thank you

very much

this works !~!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.