Ruby: how to match double quote in regex

I am trying to remove some double quotes (") from a text file using Ruby one liner with little success.

I have tried the following and some variations with no success.

ruby -pe 'gsub(/\"/,"")' < myfile.txt

      

This gives me the following error:

-e:1: Invalid argument - < (Errno::EINVAL)

      

I am running Ruby on a Win machine:

ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]

Any idea?

+2


source to share


4 answers


Seems like cmd is quoting hell - note that single quotes are meaningless in the cmd shell.

ruby -pe "gsub(34.chr,'')" < filename

      



but this is probably better:

ruby -pe "$_.delete!(34.chr)" < filename

      

+5


source


What about:



ruby -e 'puts $stdin.read.gsub(34.chr,"")' <myfile.txt

      

+1


source


ruby -pe 'gsub(/\"/,"")' myfile.txt

      

0


source


It looks like the problem is with the shell.

Your error message is from Ruby, so it seems like Ruby is receiving <

as an argument. This means that the shell does not perform any redirects.

I don't have a windows machine, so I would double-clarify that you are redirecting first. On first inspection, I think there < myfile.txt

should be<myfile.txt

0


source







All Articles