Skip to main content
added 128 characters in body
Source Link
user282457
user282457

I am trying to grep column 4 with pipe delimiter (|) and replace all double quotes within it and then enclose that string with double quotes again.

sample File:

col1|col2|col3|col4|col5col1|col2|col3|col4|col5|col6|col7|col8|col9
test|test_f|21/03/2017|"|||||USER "RIGHTa anything here|123value1|value2|value3|"|||||value"4|value5|value6|"||value"7|value8|value9

Problem is column 4 is where user can write anything, even a pipe, which is my delimiter and it breaks my process.

E.g. column 4 may be

"|||||USER "RIGHTa anything here"|||||value"4

Now I am trying to write command which goes to column 4, replace all double quotes then enclose it with double quote again so I can treat it as single string to make my process work.

Required Output for column 4 is

"|||||USER RIGHTa anything here""|||||value4"

Similarly I have do the same for column 7, required Output for column 7 is

"||value7"

Final output should look like this:

col1|col2|col3|col4|col5col1|col2|col3|col4|col5|col6|col7|col8|col9
test|test_f|21/03/2017|"|||||USER RIGHTa anything here"|123value1|value2|value3|"|||||value4"|value5|value6|"||value7"|value8|value9

please suggest.

I am trying to grep column 4 with pipe delimiter (|) and replace all double quotes within it and then enclose that string with double quotes again.

sample File:

col1|col2|col3|col4|col5
test|test_f|21/03/2017|"|||||USER "RIGHTa anything here|123

Problem is column 4 is where user can write anything, even a pipe, which is my delimiter and it breaks my process.

E.g. column 4 may be

"|||||USER "RIGHTa anything here

Now I am trying to write command which goes to column 4, replace all double quotes then enclose it with double quote again so I can treat it as single string to make my process work.

Required Output for column 4 is

"|||||USER RIGHTa anything here"

Final output should look like this:

col1|col2|col3|col4|col5
test|test_f|21/03/2017|"|||||USER RIGHTa anything here"|123

please suggest.

I am trying to grep column 4 with pipe delimiter (|) and replace all double quotes within it and then enclose that string with double quotes again.

sample File:

col1|col2|col3|col4|col5|col6|col7|col8|col9
value1|value2|value3|"|||||value"4|value5|value6|"||value"7|value8|value9

Problem is column 4 is where user can write anything, even a pipe, which is my delimiter and it breaks my process.

E.g. column 4 may be

"|||||value"4

Now I am trying to write command which goes to column 4, replace all double quotes then enclose it with double quote again so I can treat it as single string to make my process work.

Required Output for column 4 is

"|||||value4"

Similarly I have do the same for column 7, required Output for column 7 is

"||value7"

Final output should look like this:

col1|col2|col3|col4|col5|col6|col7|col8|col9
value1|value2|value3|"|||||value4"|value5|value6|"||value7"|value8|value9

please suggest.

edited tags
Link
terdon
  • 252.2k
  • 69
  • 480
  • 718
Cleanup; edited tags
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I am trying to grep col4column 4 with pipe delimiter[|]delimiter (|) and replace all double quotes within it and then enclose that string with double quotes again.

sample File:

col1|col2|col3|col4|col5

test|test_f|21/03/2017|"|||||USER "RIGHTa anything here|123

col1|col2|col3|col4|col5
test|test_f|21/03/2017|"|||||USER "RIGHTa anything here|123

Problem is col4column 4 is where user can write anything, even a pipe, which is my delimiter and it breaks my process.

eE.g. col column 4 --> "|||||USER "RIGHTa anything heremay be

"|||||USER "RIGHTa anything here

Now I am trying to write command which goes to col4column 4, replace all double quotes then enclose it with double quote again so I can treat it as single string to make my process work.

Required Output: col for column 4 --> "|||||USER RIGHTa anything here"is

"|||||USER RIGHTa anything here"

Final output should look like this:

col1|col2|col3|col4|col5

test|test_f|21/03/2017|"|||||USER RIGHTa anything here"|123

col1|col2|col3|col4|col5
test|test_f|21/03/2017|"|||||USER RIGHTa anything here"|123

please suggest.

I am trying to grep col4 with pipe delimiter[|] and replace all double quotes within it and then enclose that string with double quotes again.

sample File:

col1|col2|col3|col4|col5

test|test_f|21/03/2017|"|||||USER "RIGHTa anything here|123

Problem is col4 where user can write anything even pipe which is my delimiter and it breaks my process.

e.g. col 4 --> "|||||USER "RIGHTa anything here

Now I am trying to write command which goes to col4, replace all double quotes then enclose it with double quote again so I can treat it as single string to make my process work.

Required Output: col 4 --> "|||||USER RIGHTa anything here"

Final output should look like this:

col1|col2|col3|col4|col5

test|test_f|21/03/2017|"|||||USER RIGHTa anything here"|123

please suggest.

I am trying to grep column 4 with pipe delimiter (|) and replace all double quotes within it and then enclose that string with double quotes again.

sample File:

col1|col2|col3|col4|col5
test|test_f|21/03/2017|"|||||USER "RIGHTa anything here|123

Problem is column 4 is where user can write anything, even a pipe, which is my delimiter and it breaks my process.

E.g. column 4 may be

"|||||USER "RIGHTa anything here

Now I am trying to write command which goes to column 4, replace all double quotes then enclose it with double quote again so I can treat it as single string to make my process work.

Required Output for column 4 is

"|||||USER RIGHTa anything here"

Final output should look like this:

col1|col2|col3|col4|col5
test|test_f|21/03/2017|"|||||USER RIGHTa anything here"|123

please suggest.

Source Link
user282457
user282457
Loading