My input is:
"INTC_KEY,ABC1|OBJID,ABC2"
And I want to send the output to a file like:
DDS.INTC_KEY = REPL.OBJID AND DDS.ABC1 = REPL.ABC2
Here is what I've tried so far:
sed 's/^/DDS./g' | sed 's/|/=REPL./g' | tr '\n' '~' | sed 's/~/_N~/g' | sed 's/~$/\n/g' | sed 's/~/~\n/g' | sed 's/~/ AND/g' > ${LOG_DIR}/JOIN.tmp
Based on the single line of input, the following regular expression will transform the input into the desired output:
s/"\([^,]*\),\([^|]*\)|\([^,]*\),\(.*\)"/DDS.\1 = REPL.\3 AND DDS.\2 = REPL.\4/
This shell command shows it working:
$ echo '"INTC_KEY,ABC1|OBJID,ABC2"' | sed 's/"\([^,]*\),\([^|]*\)|\([^,]*\),\(.*\)"/DDS.\1 = REPL.\3 AND DDS.\2 = REPL.\4/'
DDS.INTC_KEY = REPL.OBJID AND DDS.ABC1 = REPL.ABC2
The regular expression basically matches four pieces of text (using the escaped parentheses), delimited by the commas and vertical bar and made available as the \1
-\4
back references for the substitution.
Note: I’ve tried to stick to using the features of standard sed
and I tested using GNU sed with the POSIXLY_CORRECT
environment variable set to 1 to emulate standard sed.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments