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
lines = File.new('foo.txt', 'r').select do |line| | |
line =~ /pattern/ | |
end |
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
require 'csv' | |
outfile = File.open('csvout.csv', 'wb') | |
CSV::Writer.generate(outfile) do |csv| | |
csv << ['c1', nil, 5] | |
csv << ['c2', 1, 2, 'abc'] | |
end | |
outfile.close | |
#also read the file and print |
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
dups = [8,1,2,1,4,4,5,7,8,5] | |
trimmed = dups.uniq |
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
lines = File.new('foo.txt', 'r').collect() do |line| | |
line.strip() | |
end |
OlderNewer