GNU sed allows specifying which occurence of a pattern (in a line) should be replaced:
First (default)
echo AAAAA | sed 's/A/X/'
XAAAA
All
echo AAAAA | sed 's/A/X/g'
XXXXX
i-th
echo AAAAA | sed 's/A/X/3'
AAXAA
To specifically target your problem with this method, you will need two modifications in sed: 1) change the beginning of the line (^) to add the opening parentheses, 2) replaces the first dash by the closing parentheses and a space.
echo 123-123-1234 | sed 's/^/(/;s/-/) /'
(123) 123-1234
Alternatively, sed allows for matching patterns and saving them (by number of occurrence) by enclosing the pattern in parentheses. In the output string you can call them by their number:
echo 123-123-1234 | sed 's/\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)/(\1) \2-\3/'
(123) 123-1234
Here [0-9] matches a digit between 0 and 9, \+ means one or more occurrences of the previous group (GNU extension to sed) and \(<pattern>\) will save the pattern and give it an index number (starting with 1 for the first and so on). Thus \([0-9]\+\)- will match one or more digits followed by a dash and will remember the digits part.
In the output \1 prints the first saved pattern from the match (i.e. [0-9]\+ ... one or more digits before the a dash. We then just use the three saved digit groups and format them as we desire.
cator the file at all. You can just doecho "$phone" | tr -d '-'directly. Even if you did need a file,catis pointless, you could just doecho "$phone" > phonedirectly.