I have a text file with a few hundred lines in it. In those lines are varying numbers of email addresses (all of the same domain). I want to change those email addresses from the format of user1@domain.com to domain\user1.
I tried using the below sed script against the source file of IDs.txt, but it errored out with the corresponding error message:
with open(IDs.txt, '+') as f:
f.write(
re.sub(r'(\w+)@domain\.com', r'domain\\\1', f.read())
)
Ran script with this command:
sed -Ef id.sed
Error:
sed: file id.sed line 2: unknown command: `f'
From what I looked up sed may not even write to files, so is this even possible to work or am I wasting time? Thanks.
---EDIT---
Sample contents of the source file:
set device-group AllPeople TestingPolicy source-user [ name1@domain.com userid@domain.com userid1@domain.com userid3@domain.com ]
set device-group AllPeople TestingPolicy11552 source-user [ userid6@domain.com userid5@domain.com userid4@domain.com userid7@domain.com ]
set device-group AllPeople TestingPolict00988 source-user userid10@domain.com
Expected output:
set device-group AllPeople TestingPolicy source-user [ domain\name1 domain\userid domain\userid1 domain\userid3 ]
set device-group AllPeople TestingPolicy11552 source-user [ domain\userid6 domain\userid5 domain\userid4 domain\userid7 ]
set device-group AllPeople TestingPolict00988 source-user domain\userid10