Question

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

I have tried the following, and some variations, without 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?

Was it helpful?

Solution

Looks like cmd 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

OTHER TIPS

How about:

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

Sounds like the problem is with the shell.

Your error message is from Ruby, so it seems Ruby is receiving the < as an argument. This means the shell isn't doing any redirection.

I don't have a Windows machine handy so I'd double check that you're getting the redirection right first. On first inspection I think the < myfile.txt should be <myfile.txt

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top