Created
July 15, 2014 11:58
-
-
Save Epigene/903a7237b9d36388c867 to your computer and use it in GitHub Desktop.
Grep-loop in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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