Search code examples
shellunixawksedksh

Replace /" from the 14th column of the file in unix shell script ksh


I have one file which has 10000+ records. There are some bad records which has /" in between the value like below. This is comma delimeter file. I cannot use -E GNU option.

"22-11-2020","ABCD",,"ABCD/4400","7644","NY","NY","LAX","ABC","16-09-2023","25-09-2023","02-10-2023","660802","993 14\" X 8\"","28-09-2023",4,"CA",2586,"AA",65.850000,6895.200000,"01-11-2023"

I need to remove/replace " from 14th column. I tried below command but its replacing all the double quotes, but not the \ .

sed 's/'\"'/''/g' File

Need the Output as below :

"22-11-2020","ABCD",,"ABCD/4400","7644","NY","NY","LAX","ABC","16-09-2023","25-09-2023","02-10-2023","660802","993 14 X 8","28-09-2023",4,"CA",2586,"AA",65.850000,6895.200000,"01-11-2023"

Solution

  • Assuming that all you want is to replace the string \" with the empty string, the following sed command should work:

    sed 's/\\"//g' filename
    

    If you only want to do this in the 14th column, you could use awk;

    awk  'BEGIN {FS=","; OFS=",";} {gsub(/\\"/, "", $14); print}' filename