Skip to content
Advertisement

Python to remove extra delimiter

We have a 100MB pipe delimited file that has 5 column/4 delimiters each separated by a pipe. However there are few rows where the second column has an extra pipe. For these few rows total delimiter are 5.

For example, in the below 4 rows, the 3rd is a problematic one as it has an extra pipe.

JavaScript

Is there any way we can remove an extra pipe from the second position where the delimiter count for the row is 5. So, post correction, the file needs to look like below.

JavaScript

Please note that the file size is 100 MB. Any help is appreciated.

Advertisement

Answer

Source: my_file.txt

JavaScript

Code

JavaScript

Result: my_file_parsed.txt

JavaScript
Advertisement