Skip to content

Instantly share code, notes, and snippets.

@Epigene
Created July 15, 2014 11:58
Show Gist options
  • Save Epigene/903a7237b9d36388c867 to your computer and use it in GitHub Desktop.
Save Epigene/903a7237b9d36388c867 to your computer and use it in GitHub Desktop.
Grep-loop in Ruby
#!/usr/bin/env ruby
# Usage: paste in a file and call it in console with `ruby filename`
# inicializē datu struktūras
musejie = []
`rm out.csv` ; `touch out.csv`
#ielasa no faila pasaucot shell command
musejie = `cat musejie.csv`.split.uniq # musejie.csv satur ierakstus katru jaunā rindiņā caur kuriem laist ciklu
puts "Ielasīju #{musejie.size} ierakstus."
total = musejie.size
#Iet cauri iepriekš ielasītajam masīvam un, šeit, sauc grep komandu, lai meklētu katru ierakstu norādītā failā
musejie.each_with_index do |epasts, index|
`grep #{epasts} mailigen.csv >> out.csv` # mailigen.csv satur pārmeklējamos datus
puts "#{index+1}/#{total} : #{epasts}" #izvada paskaidrojošu tekstu skripta izpildes laikā
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment