awk - print

Hi all,

I have script below:

#!/bin/sh

$name=blah

awk -F: -v user="$name" '$1 == user{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp

based on above, it will only print one line which is "blah" username details.

What do i need to do to print all contents of shadow file including "modified" blah user?

awk -F:  '{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp

Is this what you want?

hi jim,

awk -F: '{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp ---> will show all lines within shadow file but not including the one i has edited.
e.g:
name=blah
awk -F: -v user="$name" '$1 == user{print $1 ":" $2 ":" DUMMY ":" $4}' /etc/shadow > /tmp/shadow.tmp

From the script above, it will only print blah::DUMMY: at shadow.tmp
what i need is to print the rest of the users from shadow file including the modified.
e.g:

man::13994::::::
nagios:!:13994:0:99999:7:::
named:!:13994:0:99999:7:::
news:
:13994::::::
nobody:*:13994::::::
ntp:!:13994:0:99999:7:::
blah::DUMMY:

instead of only blah::DUMMY:

Something like this?

awk -F: -v user="$name" '$1==user{$3="DUMMY"}1' OFS=":" /etc/shadow > /tmp/shadow.tmp

Regards

how about

cat /etc/shadow

Let's set the OFS

awk -v user="$name" '{FS=OFS=":"}$1==user{$3="DUMMY"}1'  /etc/shadow > /tmp/shadow.tmp

The above will show the original, not the modified, version of blah :slight_smile: