0

I have a test.csv like so:

83451031,2019-07-04,0,0,0,0,--,0,--,0,0,0,,,,--,--,--,--,--,--,--,--,,,,,,,,,,
1730632031,2019-07-05,0.6023,3200000,0.1789,0.1768,June,0.0097,5,381.1,515.4,46300,11.67,68.97,19.36,4.33,67.51,22953,49,0.0053,Typical,8.3,377,,--,--,,--,--,,--,--,

I want to replace -- with nothing i.e. blank

I've tried the following:

$ sed 's/--/' test.csv > test.csv
$ sed -i 's/--/' test.csv
$ sed -i "s/--/" test.csv
$ sed -i "s/--//" test.csv
$ sed -i "s/--//g" test.csv
$ sed -i "s/'--'//" test.csv
$ sed -i "s/'--'//g" test.csv
$ sed -i "s/'--'/''/" test.csv

All of which gives an error of:

sed: 1: "test.csv": undefined label 'est.csv'

Since -- signifies the end of command options, I assume that's the problem?

I just want to be able to replace all occurrences of -- in the CSV to blank.

kvantour
  • 25,269
  • 4
  • 47
  • 72
AK91
  • 671
  • 2
  • 13
  • 35

1 Answers1

1

try

sed 's#--#  #g' 

Demo:

$echo 5"83451031,2019-07-04,0,0,0,0,--,0,--,0,0,0,,,,--,--,--,--,--,--,--,--,,,,,,,,,,"  | sed 's#--#  #g' 
583451031,2019-07-04,0,0,0,0,  ,0,  ,0,0,0,,,,  ,  ,  ,  ,  ,  ,  ,  ,,,,,,,,,,
$

Digvijay S
  • 2,665
  • 1
  • 9
  • 21
  • This doesn't answer OP's quesion IMO. OP is using `sed` from MacOS, which is causing errors because of not providing the inplace extension – Inian Jul 23 '20 at 07:14
  • That works in terms of display output but when trying to output to file it removes everything i.e. `sed 's#--# #g' test.csv > test.csv` returns an empty test.csv file – AK91 Jul 23 '20 at 07:19
  • 1
    @AK91: You cannot re-direct to the same file. The `>test.csv` empties the file before running `sed`. Use the `-i.bak` or `-i ''` option for inplace edit. See the linked question – Inian Jul 23 '20 at 07:28