I have a csv file which is supposed to contain 4 columns of data which include a product number, a title, a url and a price. Each column is separated by a | delimiter (this has to be maintained, there are other reasons why I can't switch to an alternative delimiter which I won't go into here). As can be seen in the bottom entry (which is the problem entry in this example) the title contains a pipe, which breaks the pattern, which could potentially causes issues if the data needs to be imported into a database. 5456435121|The making of the blue album|https://www.example1.co.uk|551321354567|Wow this example has no imagination|https://www.cherrypickers.co.uk|895456456456|King of the Barbarians | Last Man Standing|https://www.babarians.co.uk|79What I would like to know is, how can I run a command which could effectively analyse the file, and for every line where there are more than 3 pipes( i.e. every line where the title contains a pipe) then delete the 2nd one in that line. This would effectively allow me to remove the pipe(s) in the title if there is one or more present. I don't know how to achieve it.I would like the file to look like this once processed:5456435121|The making of the blue album|https://www.example1.co.uk|551321354567|Wow this example has no imagination|https://www.cherrypickers.co.uk|895456456456|King of the Barbarians Last Man Standing|https://www.babarians.co.uk|79
If there are more than x number of pipes in a csv line, then delete the 2nd instance
shell script;text processing;csv
sed -r ':;s/(\|.*)\|(.*\|.*\|)/\1\2/;t'Deletes every pipe that is preceeded by one and followed by two pipes.If you want to edit the file in place use -i option.