sed -E "s!^[[:digit:]]\{4\}!0,0,&!" massmurder.csv|sed -E "s!\([[:digit:]]\)/\([[:digit:]]\(4\)\)!\1/0/\2!"The first command does convert YYYY to 0/0/YYYY. The second command should convert M/YYYY to M/0/YYYY. But the second command produces:
sed: -e expression #1, char 47: invalid reference \2 on 's' command's RHSWhat am I doing wrong?
I think you've got some typos in your example, but it looks like you don't want to use -E. (I will admit I probably don't know sed as well as you; I never used it a lot.)
ReplyDeleteI eventually came up with this variation:
sed "s/[[:digit:]]\{4\}/0\/0\/&/" x.csv | sed "s=\([[:digit:]]\)/\([[:digit:]]\(4\)\)=\1/0/\2="
With x.csv looking like this: 1,a,b,1234,1/1/1900, the above produced the following output: 1,a,b,0/0/1234,1/1/1900
Note that the "invalid reference" went away when I stopped using -E.