perl or sed substitution

how would you use change the second field in the /etc/shadow file to change whatever is there to read !!nopasswd!! using either perl or sed ?
Who is Participating?
point_pleasantConnect With a Mentor Commented:
just as an aside if you don't want to replace root

awk -F: -v OFS=: '!/^root:/ {$2 = "!!nopasswd!!"}{ print }' /etc/shadow
awk -F: -v OFS=: '{$2 = "!!nopasswd!!"; print }' /etc/shadow
If the goal is locking out the user then under Solaris and Linux you can just run as root

passwd -l username
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

lolaferrariAuthor Commented:
what is the difference between IFS and OFS?
man bash
       IFS    The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command.  The default value is ``<space><tab><newline>''.

man awk
       OFS    output field separator (default blank)

So IFS is a separator in the shell (and perhaps some other programs) that is used when interpreting fields.
and OFS is a separator in awk (and perhaps some other programs) that is used when displaying fields.
lolaferrariAuthor Commented:
I should have looked there to - thank you very much Ozo for the explanation.
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.