Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Replacing all but the first and last double quote in a line with a single quote with awk

$
0
0
From:
Code:

1,2,3,4,5,This is a test
6,7,8,9,0,"This, is a test"
1,9,2,8,3,"This is a ""test"""
4,7,3,1,8,""""

To:

Code:

1,2,3,4,5,This is a test
6,7,8,9,0,"This; is a test"
1,9,2,8,3,"This is a ''test''"
4,7,3,1,8,"''"

Is there an easy syntax I'm overlooking? There will always be an odd number of quotes (0,2,4,6,etc). If present the first quote will follow a comma and if present the final quote will precede a LF.

Prior to this, I have replaced any LF (but not CR+LF) with | , than replaced any CR+LF with LF and replaced any , in the rightmst field with ; (by using a loop to look for more csv columns and OFS=; ). I was not aware of the "" mean " thing in the .csv standard however.

Mike

Viewing all articles
Browse latest Browse all 16232

Latest Images

Trending Articles



Latest Images