-2
,"some values1","some values2",Not Processed,0,

Is there any way I could replace the above pattern, irrespective of whatever values come in some values1 or some values2 with the lines below,

,,,Not Processed,0,

This string is just a part of a large file I have.

tripleee
  • 175,061
  • 34
  • 275
  • 318
vijith
  • 11
  • 5
  • please try to be more clear .. what you want to replace and with what .... we will definatly try to help you – Puneet Sinha Jan 18 '19 at 07:01
  • @PuneetSinha I want to replace with empty values as I mentioned in the desired O/P, – vijith Jan 18 '19 at 07:07
  • How about Perl? `perl -i.bak -wple 's!^,"[^"]+","[^]",!,"","",!' file.csv` – Corion Jan 18 '19 at 07:20
  • @Corion could you please tell me how to do that in sed, also the lines I mentioned in the question are a part of a larger string, in one line the first value might be in 5th position and in the next line it may vary . Only the pattern which I mentioned in the question remains unchanged. – vijith Jan 18 '19 at 07:25
  • ... sorry (too late to edit) `How about Perl? `perl -i.bak -wple 's!^,"[^"]+","[^"]",!,"","",!' file.csv`` – Corion Jan 18 '19 at 07:25
  • 2
    Then please [edit] your question and write there what the constant pattern is and what the variable pattern is. From what you've shown, it is completely unclear where the pattern starts and ends. – Corion Jan 18 '19 at 07:26
  • 1
    Maybe try `perl -i.bak -wple 's!,"[^"]*","[^"]*",Not Processed,0!,"","",Not Processed,0,!'` – Corion Jan 18 '19 at 07:27
  • Possible duplicate of https://stackoverflow.com/questions/20425763/replace-in-a-csv-file-value-of-a-column – tripleee Jan 18 '19 at 08:24

1 Answers1

0

This solves the problem I believe:

test_data() {
  cat <<EOF
  ,"val1,val2...","val1,val2,val3..",Not Processed,0,
  ,"val1,val2..","",Not Processed,0,
  ,"","val1,val2,val3....",Not Processed,0,
EOF
}

test_data | sed -e 's/\(.*\),"[^"]*","[^"]*",\(Not Processed,0,\)\(.*\)/\1,,,\2\3/g'

Output:

▶ bash data.sh
  ,,,Not Processed,0,
  ,,,Not Processed,0,
  ,,,Not Processed,0,
Alex Harvey
  • 14,494
  • 5
  • 61
  • 97