Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby get line from a file

# open the file
File.open('foo.txt') do |file|
  # iterate over each line with its index
  file.each_line.with_index(1) do |line, number|
    puts "#{number}: #{line}"
  end
end
# since we passed a block, the file is automatically closed after `end`
Comment

ruby get line from a file

# open the file
File.open('foo.txt') do |file|
  # iterate over each line
  file.each_line do |line|
    puts line
  end
end
# since we passed a block, the file is automatically closed after `end`
Comment

ruby get line from a file

# open the file
file = File.open('foo.txt')

# iterate over each line
file.each_line do |line|
  puts line
end

# close the file afterwards
file.close
Comment

ruby read file line by line

File.readlines('foo').each do |line|
	puts line
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: write heroku logs 
Ruby :: hello world ruby 
Ruby :: rails class sti reminders 
R :: r convert accented characters 
R :: r clear variables 
R :: list all installed packages in r 
R :: check type of column in r 
R :: find data type of vector r 
R :: how to select all the records above a specific datetime in r 
R :: how to transform days in years R 
R :: merge multiple objects in r 
R :: data table R select several columns 
R :: how to split a column in r 
R :: how to build random forest in r 
R :: how to change the numbering of rows in r 
R :: rep in r 
R :: vars() in R 
R :: r number of blanks in the data 
R :: how to get quantile summary statistics in r summarise 
R :: color code in R 
R :: how to source all fies from a directory in r 
R :: tidytext extract url r 
R :: formatc in r 
R :: extract df from lm in r 
R :: change order of levels, reference 
R :: geom_abline vertical line 
R :: how to combine multiple time series in r 
Rust :: read file buffer rust 
Rust :: read file rust 
Rust :: rust test std out 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =