Reputation: 2973
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?
Upvotes: 2
Views: 2562
Reputation: 247210
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
Upvotes: 5
Reputation: 138210
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
Upvotes: 0
Reputation: 31468
How about:
ruby -e 'puts $stdin.read.gsub(34.chr,"")' <myfile.txt
Upvotes: 1