My file is comma delimeted, only 3rd field is enclosed in doubled quotes, but in that filed getting multi double quotes, multi commas as well. How to replace double quotes with some rare chars like ~` without disturbing rest data
Input:
It's actually easy to do with PERL, PHP, Python, Javascript or any language which has basic text processing functions (split, string replace, etc):
Read each line as a string and then:
Split the string on commas into an array and create a new string from the elements of the array minus the first, second, and last element. This yields:
"ABC, DEF, ("SSS")"
Then remove the first and last char (the beginning and ending quotation marks) in the string, which yields:
ABC, DEF, ("SSS")
The replace each quotation mark remaining with your special chars:
ABC, DEF, (~`SSS~`)
Add the quotation marks back to the beginning and the end:
"ABC, DEF, (~`SSS~`)"
and reassemble with commas with the first, second and last elements of the array (this is called implode in PHP), i.e.
(PHP 4, PHP 5, PHP 7)
implode — Join array elements with a string
100,DAVID, "ABC, DEF, (~`SSS~`)",900
This little algorithm works for both test cases provided by @rajeshkumare , easily.