Skip to main content
added 16 characters in body
Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107

I am unsure about your intend to remove leading _ this might lead to chown: _user not found when chowning

try

awk -F: '/^#/ { next } {printf "chown %s \"%s\"\n",$1,$6} ' my_etc_passwd

where

  • -F: tell awk to use : as separator
  • /^#/ { next } skip line starting with #
  • likewise add /^_/ { next } to skip line starting with _ (if need be)
  • next pattern/action print chown command.

If result look OK, just pipe to bash

I am unsure about your intend to remove leading _ this might lead to chown: _user not found when chowning

try

awk -F: '/^#/ { next } {printf "chown %s \"%s\"\n",$1,$6} ' my_etc_passwd

where

  • -F: tell awk to use : as separator
  • /^#/ { next } skip line starting with #
  • likewise add /^_/ { next } skip line starting with _
  • next pattern/action print chown command.

If result look OK, just pipe to bash

I am unsure about your intend to remove leading _ this might lead to chown: _user not found when chowning

try

awk -F: '/^#/ { next } {printf "chown %s \"%s\"\n",$1,$6} ' my_etc_passwd

where

  • -F: tell awk to use : as separator
  • /^#/ { next } skip line starting with #
  • likewise add /^_/ { next } to skip line starting with _ (if need be)
  • next pattern/action print chown command.

If result look OK, just pipe to bash

Source Link
Archemar
  • 32.3k
  • 18
  • 75
  • 107

I am unsure about your intend to remove leading _ this might lead to chown: _user not found when chowning

try

awk -F: '/^#/ { next } {printf "chown %s \"%s\"\n",$1,$6} ' my_etc_passwd

where

  • -F: tell awk to use : as separator
  • /^#/ { next } skip line starting with #
  • likewise add /^_/ { next } skip line starting with _
  • next pattern/action print chown command.

If result look OK, just pipe to bash