I have been using pass for to store my passwords via GPG. I am trying to change an old username to a new username in dozens of accounts all at once.

Each username is in a "Username:" comment under the password. i.e. a gpg encrypted file ~/.password-store/amazon is like the following:

Username: [email protected]
URL: amazon.com
OTP: ... 

I can't just replace all occurrences of the old username, because sometimes the username appears in other comments. One such example is in OTP codes. This seems like a relatively simple problem, I just don't want to run the risk of clobbering all occurrences of the old username.

1 Answer 1


You can use the following command:

sed -i 's/^\(Username: \) *[email protected]$/\[email protected]/' *

This command replaces in each file each line that starts with "Username: [email protected]" and replaces it with "Username: [email protected]"

Note: Make a backup before playing with this command because it replaces the original files with new ones. This is the "-i" option of the "sed" command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .