The proper way to deal with CSV is to use a proper csv parser.
Given:
$ cat file
# Director, Movie Title, Year, Comment
Ethan Coen, No Country for Old Men, 2007, none
Ethan Coen, "O Brother, Where Art Thou?", 2000, none
First issue, your example has a two character delimiter of ', ' vs a single comma ','. That will throw off most csv parsers unless they support multi character delimiters. For example, csvkit does not support multi character delimiters. (The place where it fails is on quoted fields since if the csv parser is looking for ," as the start of a quoted field, it fails with , "...)
The lightest weight but full featured csv parser commonly available at the command line is in ruby.
With ruby, you can do:
$ ruby -rcsv -ne 'puts (CSV.parse $_, col_sep:", ").join("|")' file
# Director|Movie Title|Year|Comment
Ethan Coen|No Country for Old Men|2007|none
Ethan Coen|O Brother, Where Art Thou?|2000|none
If you want the replacement to also be '| ' vs the single character delimiter of '|' you can do:
$ ruby -rcsv -ne 'puts (CSV.parse $_, col_sep:", ").join("| ")' file
# Director| Movie Title| Year| Comment
Ethan Coen| No Country for Old Men| 2007| none
Ethan Coen| O Brother, Where Art Thou?| 2000| none
Note that O Brother, Where Art Thou? is no longer quoted since the ', ' is no longer a delimiter.
To even be more proper you would use the csv module to re-encode back into a proper RFC 4180 compliant file.
Suppose you wanted to fix the ', ' into a compliant ',' and maintain the quoted fields. Our single line of Ruby does not do that.
Instead:
$ ruby -rcsv -ne 'out=(CSV.parse $_, col_sep:", ").map do |row|
row.to_csv(:col_sep=>",")
end
puts out' file
# Director,Movie Title,Year,Comment
Ethan Coen,No Country for Old Men,2007,none
Ethan Coen,"O Brother, Where Art Thou?",2000,none
Or into a '|':
$ ruby -rcsv -ne 'out=(CSV.parse $_, col_sep:", ").map do |row|
row.to_csv(:col_sep=>"|")
end
puts out' file
# Director|Movie Title|Year|Comment
Ethan Coen|No Country for Old Men|2007|none
Ethan Coen|O Brother, Where Art Thou?|2000|none