How to use Sed command to get following output?

Eshan Chintawar

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
Anthony Geoghegan

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to use the following command in Jenkins pipeline/Linux

not able to get proper output for sed command

How to get the output of a command

Bash - how to preserve newline in sed command output?

How to use sed to get the required output?

Use output of one command as replacement text in sed

HTML tables: how to get the following output?

How to get following output in sql pivot

how to get the following output of the code snippet?

How to pass output of command to sed

How to use variables in sed command

How to get the output for the following code?

How to get the output for the following?

How to use ! in the sed command?

How to use variables in sed command

How can I fix the following sed command?

How to use substitute command in unix(vi or sed) to achieve the following results

How to use variable in sed command

How to use numbers in sed command?

How to use sed to print a portion of an output from a command

How to redirect output to a specific file into a sed command?

How to use the following curl post command in java?

How to use sed/awk to replace the original file and get the following desired output?

How to get output using the following tables in SQL?

How can I use a command output as a input string in the command "sed -i '10istring' a.txt"

How to use a single sed command for this?

How to get the following output in asyncio gather

How to use PowerPivot to Transform the following dataset into the following desired output

How to pipe the output of a sed command into a function in unix

TOP Ranking

HotTag

Archive