Operating System - HP-UX
1754280 Members
3292 Online
108813 Solutions
New Discussion юеВ

Re: change character in the passwd file

 
OldSchool
Honored Contributor

Re: change character in the passwd file

While some of the GNU utilities have the ability to do "in-place" changes (as does perl, i believe) that doesn't work for awk that I know of. One liner like:

awk -f awk.scr /etc/passwd > (temp_file); cp (temp_file) /etc/password


Should get what you want
OldSchool
Honored Contributor

Re: change character in the passwd file

or something like:

cp /etc/passwd (tempfile); awk -f awk.scr (tempfile) > /etc/passwd
Jocelyn Dinel
Occasional Advisor

Re: change character in the passwd file

unfortunately, the result is good but not replace directly in the file, only put the line where the :: is find
jocelyn dinel
Dennis Handly
Acclaimed Contributor

Re: change character in the passwd file

>the result is good but only put the line where the :: is found

Try this:
awk -F: '
{
if ($2 == "")
$2 = ",.."
print $0
}' /etc/passwd > (temp file here)
OldSchool
Honored Contributor

Re: change character in the passwd file

I told you...."will find any lines with :: after the login name"

It does nothing with the lines that don't match.

Dennis's version should handle that case as well, by changing the second field if required, and always printing each line.....

That may (or may not be) *exactly* what you need either, but they are places for you to start from....