0
私はファイルsay-list.txtから読み込み、list.txtの文字列がディレクトリ内の複数のファイルに存在するかどうかを確認しています。 (E:\ work ...)。以下は私のコードです。期待通りに動作します。ディレクトリ内のファイルのいずれかからクラスの\ 234ヘクタールとキャップの\ 7y6t5 - Rubyアクセス配列の値
pool = ''
rows = Array[]
id_files = Dir.glob("E:\work'*-access.txt")
value=File.open('E:\nando\list.txt').read
value.each_line do |line|
line.chomp!
id_files.each do |file_name|
text = File.read(file_name)
new_content = text.gsub(/#{Regexp.escape(line)}\,\s/, '').gsub(/#{Regexp.escape(line)}/, '')
unless text == new_content
text.each_line do |li|
if li.match(/#{Regexp.escape(line)}/) then
rows << li # I didn't complete the array part
puts rows[0]
puts rows[1]
pool = li.split(" ")[0]
end
end
File.open('E:\Removed_users.txt', 'a') { |log|
log.puts "Removed from: #{file_name}"
log.puts "Removed id : #{line}"
log.puts "Removed from row :#{pool}"
log.puts "*" * 50
}
File.open(file_name, "w") { |file| file.puts new_content }
end
end
end
私は文字列をfile.Egをログに以下の形式で印刷するには、コードを強化しようとしています。
Removed class\234ha from row = id and dept
Removed cap\7y6t5 from row = id
E:\作業\サンプル-access.txtに
CDA created on September 20th 1999
Owner: Edward Jenner
Access IDs,
id = class\234ha, class\poi23, class\opiuj, cap\7y6t5
dept = sub\6985de, ret\oiu87, class\234ha
rec = ret\oiu87
私はそれだけで一つのtime.i.e.のために印刷させることができますよクラスの\ 234ヘクタールのために私は期待どおりに
Removed from: E:\work\sample-access.txt
Removed user : class\234ha
Removed from row = id and dept
私は、配列のオプションを使用してみましたする必要がありますが、私は結果が届かない理想的
Removed from: E:\work\sample-access.txt
Removed user : class\234ha
Removed from row = id
として出力を得ていると私はしたくありません完全にコードやロジックを書き換えます。 Rubyのエキスパート、どんな提案も本当に役に立ちます。ありがとう。
ご提案をお寄せいただきありがとうございますけれどもを見落とすdidntの願ってい
である。そのような値を追加する代わりに次のごとに単一の値を印刷行から削除サンプルaccess.txtに :行 'から削除行から削除サンプルaccess.txtに :ID から削除R:IDとDEP から削除ate-access.txt 行から削除されました:depとautomation' – dev
申し訳ありませんがコメントを理解できません。各行(= id)には、現在のファイルに対して、それが削除されたすべてのセクションがループ内に保持されます。 'pool'は、ファイルごとにセクション(=行)を含みます。あなたの質問から答えが得られるはずです。 – insider
お時間をいただきありがとうございます。私は別の方法で働いた。 – dev