Reputation: 157
test.sed
s/^(\([0-9][0-9][0-9]\))\([[:space:]][0-9][0-9][0-9]\)-\([0-9][0-9][0-9][0-9]\)/(XXX)\2-\3/
Command I used to run test.sed:
sed -f test.sed file.txt
file.txt:
(123) 123-2345
(456) 416-2345
(111) 905-2345
(222) 905-2345
Output:
(XXX) 123-2345
(XXX) 416-2345
(XXX) 905-2345
(XXX) 905-2345
Expected Output:
(XXX) 123-2345
(XXX) 416-2345
(ZZZ) 905-2345
(ZZZ) 905-2345
Hello, basically this just change all phone number to form like "(XXX) 123-1234". But I want to put one more condition that It will not change numbers in parenthesis to XXX but to ZZZ if original numbers in the parenthesis was 111 or 222.
How can I do this in sed?
Thank you very much.
Upvotes: 1
Views: 1186
Reputation: 3363
sed -E 's/\((111|222)\)/(ZZZ)/;s/\([0-9]{3}\)/(XXX)/' file.txt
Upvotes: 2