今日やる事
勉強したこと
file_data = []
count_sum = 0
size_sum = 0
bytesize_sum = 0
connection_total = []
if ARGV.length > 0
ARGV.each do |filename|
file_read = File.read(filename)
file_data << file_read.count("\n").to_s.rjust(8)
file_data << file_read.split(" ").size.to_s.rjust(8)
file_data << file_read.bytesize.to_s.rjust(8)
file_data << File.basename(filename).to_s.rjust(6)
file_data << "\n"
count_sum += file_read.count("\n")
size_sum += file_read.split(" ").size
bytesize_sum += file_read.bytesize
connection_total << count_sum.to_s.rjust(8)
connection_total << size_sum.to_s.rjust(8)
connection_total << bytesize_sum.to_s.rjust(8)
connection_total << "\n"
end
else
puts STDIN.read
end
puts file_data.join("")
puts connection_total.join("")
file_data = []
count_sum = 0
size_sum = 0
bytesize_sum = 0
connection_total = []
if ARGV.length > 0
ARGV.each do |filename|
file_read = File.read(filename)
file_data << file_read.count("\n").to_s.rjust(8)
file_data << file_read.split(" ").size.to_s.rjust(8)
file_data << file_read.bytesize.to_s.rjust(8)
file_data << " "
file_data << File.basename(filename)
p File.basename(filename).class
file_data << "\n"
count_sum += file_read.count("\n")
size_sum += file_read.split(" ").size
bytesize_sum += file_read.bytesize
connection_total << count_sum.to_s.rjust(8)
connection_total << size_sum.to_s.rjust(8)
connection_total << bytesize_sum.to_s.rjust(8)
connection_total << "\n"
end
else
puts STDIN.read
end
puts file_data.join("")
puts connection_total.join("")
file_data = []
count_sum = 0
size_sum = 0
bytesize_sum = 0
if ARGV.length > 0
ARGV.each do |filename|
file_read = File.read(filename)
file_data << file_read.count("\n").to_s.rjust(8)
file_data << file_read.split(" ").size.to_s.rjust(8)
file_data << file_read.bytesize.to_s.rjust(8)
file_data << " "
file_data << File.basename(filename)
file_data << "\n"
count_sum += file_read.count("\n")
size_sum += file_read.split(" ").size
bytesize_sum += file_read.bytesize
end
else
puts STDIN.read
end
connection_total = []
connection_total << count_sum.to_s.rjust(8)
connection_total << size_sum.to_s.rjust(8)
connection_total << bytesize_sum.to_s.rjust(8)
connection_total << " total"
total = []
total << connection_total.join("")
count = []
count << file_data.join("")
puts count.push(total)
【 wc 】コマンド――テキストファイルの文字数や行数を数える:Linux基本コマンドTips(62) - @IT