I have a file, in which I have to find and change strings by specific pattern (phone number). The regex is:
^\+[0-9]{3} \([0-9]{2}\) [0-9]{7}$
When I use it in command:
grep "^\+[0-9]{3} \([0-9]{2}\) [0-9]{7}$" -E filename
It works. But when I try to use it in sed to replace all parenthesis by spaces and add spaces in 13 and 15 position, it doesn't works and I don't have ideas why.
My variants are:
sed '/^\+[0-9]{3} \([0-9]{2}\) [0-9]{7}$/s/[()]//' filename
(only for replacing parenthesis)
sed -e '/^\+[0-9]{3} \([0-9]{2}\) [0-9]{7}$/s/[()]//' -e '/^+[0-9]{2} ([0-9]{2}) [0-9]{7}/s/./& /11;s/./& /14' filename
file structure:
+380 44 123 45 67
+380 (44) 1234567
+350 (56) 1454557
+330 (76) 1255557
+380 44 3534 45 67
+320 (45) 1237887
+310 (54) 1939997
adasd
asdddddddddddd
sssdad
expected output:
+380 44 123 45 67
+380 44 123 45 67
+350 56 145 45 57
+330 76 125 55 57
+380 44 3534 45 67
+320 45 123 78 87
+310 54 193 99 97
adasd
asdddddddddddd
sssdad
-Eoption tosedcommand as well, which you use withgrepfor same purpose of using extended regex