I’m a bit stuck with a unix command.
I have a file called file.txt with the following content:
Customer1
name=Alice
pass=unix
dob=
Customer2
name=Destroyer
pass=windows
dob=
What I basically want is to use a unix command that would allow me to grep for the customer (i.e Customer1) then give its dob a value, say for example dob=1912
so the file.txt will become like
Customer1
name=Alice
pass=unix
dob=1912
I’ve been working with sed, here’s the command that I formulated:
sed “s/$(awk ‘c–>0;/Customer1/{c=3}’ file.txt | tail -1)/dob=1234/g” -i file.txt
This however will replace ALL occurrences of dob with dob=1234 (quite obvious).
Can someone give me a hint on how to lock on the specific dob for each customer and replace it?
Thanks in advance.
awk can do it by itself. see the one liner below:
test : change customer1’s dob value to 7777:
updated:
updated again
updated with sed
actually, using sed (with convenient -i option) to handle this is also possible. I didn’t understand your requirement correctly, I thought you only want the specific Customer Block. so I picked awk. Now comes the sed version: