virt-edit has a handy
-e option that lets you do replacements on files. For example this wipes out your root password:
virt-edit domname /etc/passwd -e 's/^root:.*?:/root::/'
How can you do the same thing from guestfish or the libguestfs API?
There’s no support for this operation directly in the API, but you can download the file, use sed/perl/whatever on it locally, and upload it, and that is essentially the same thing that virt-edit is doing.
Here’s how to do that easily in guestfish:
$ guestfish --rw -i -d domname ><fs> download /etc/passwd /tmp/passwd ><fs> ! sed 's/^root:[^:]\+:/root::/' /tmp/passwd > /tmp/passwd.new ><fs> upload /tmp/passwd.new /etc/passwd
! before a command runs a local command.