I have a regex and replacement pattern that have both been tested in Notepad++ on my input data and work correctly. When I put them into a sed expression, however, nothing gets matched.
Here is the sed command:
# SEARCH = ([a-zA-Z0-9.]+) [0-9] (.*)
# REPLACE = \2 (\1)
sed -e 's/\([a-zA-Z0-9.]+\) [0-9] \(.*\)/\2 \(\1\)/g'
Here is a sampling of the data:
jdoe 1 Doe, John
jad 1 Doe, Jane
smith 2 Smith, Jon
and the desired output:
Doe, John (jdoe)
Doe, Jane (jad)
Smith, Jon (smith)
I have tried removing and adding escapes to different characters in the sed expression, but either get nothing matched or something along the lines of:
sed: -e expression #1, char 42: invalid reference \2 on `s' command's RHS
How can I get this escaped correctly?