1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
begin =begin File.foreach('hist.txt') do |ln| next if ln =~ /^.{0,4}$/ next if ln =~ /^c\s/ puts ln end =end =begin File.open('hist.txt') do |f| f.each_line do |l| puts l end end =end =begin File.open('hist.txt') do |f| f.read.split(/\n/).sort.each do |l| puts l end end =end =begin File.open('hist.txt','r+') do |i| #rは読込専用,r+は読込書込だけど開いても書き込まなれければそのまま File.open('hist_back.txt','w+') do |o| #wは新規作成 o.write(i.read) #ここまでは処理されるが以下は処理されない i.puts o.read.split(/\n/).uniq #putsは一行ずつ end end =end File.open('hist.txt','r') do |i| File.open('hist_back.txt','w') do |o| o.write(i.read) end end File.open('hist_back.txt','r') do |i| File.open('hist.txt','w') do |o| o.puts i.read.split(/\n/).uniq end end rescue => e puts e.message end |
bash_historyの重複削除
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
begin File.open('.bash_history','r') do |i| File.open('.bash_history.bak','w') do |o| o.write(i.read) end end File.open('.bash_history.bak','r') do |i| File.open('.bash_history','w') do |o| o.puts i.read.split(/\n/).uniq end end rescue => e puts e.message end |