I have this command line input in Windows:
dir /b | ruby -ne 'f=$_.chomp;File.read(f).each_line{|line| print f if line =~ /helloworld/};'
This line is to find all files under current directory with helloworld
in it. (I understand there are many other ways to do this but the post is not focusing on that)
My question is:
This line gives error saying line is not a valid command
. Then I realized |
in Ruby as a brace for block variable is a pipe sign in cmd. I tried to change the whole line into double quoted and escape the | sign but no success. How can I escape the vertical bar |?
Please don't answer other ways to do the task such as using other tools like grep, find, sed or awk, or change the block into for loop.