Ruby script to check if a string is within a file? Ruby script to check if a string is within a file? bash bash

Ruby script to check if a string is within a file?


Hey You can use FasterCSV to open and loop thru the records.

        FasterCSV.foreach("#{file_path}") do |row|         puts row[0]#row[0] is the first column only        end 


If we are using bash, than it will be:

fgrep -x -f patternfile.txt data.csv | awk '{print $2}'

as a simplies way to get second column from a grep results


To check if a file has a particular string in it at least once:

IO.readlines(filename).map(&:chomp).include?("somestring")