Ruby Txt is a common CSV tool.
Require 'csv 'namespace: sys_file_conver do desc "Import txt data to csv" task: txt_to_csv =>: environment do amount = 100 head_hash = {'reconciliation file name' => [12], 'Merchant ID '=> [15], 'Merchant type' => [4], 'liquidation date' => [8], 'total ratio number' => [12], 'total right' => [15, amount], 'Total payment ratio '=> [12], 'total payment amount' => [15, amount], 'total refund ratio '=> [12], 'Total refund amount '=> [15, amount], 'total revocation ratio' => [12], 'total revocation '=> [15, amount]} body_hash = {'liquidation date' => [8], 'accounting date' => [8], 'Card No' => [19], 'transaction type' => [4], 'transaction sync' => [15, amount], 'recorded amount' => [15, amount], 'service fee amount '=> [15, amount], 'serial number' => [6], 'transaction date and time' => [10], 'terminal number' => [8], 'Merchant number' => [15], 'Merchant type' => [4], 'accepting organization No. '=> [6], 'System search no.' => [12], 'authorization No. '=> [6], 'Channel type' => [2], 'payment cards' => [2], 'order No. '=> [40]} txt_file_path = ENV ['txt _ file_path'] | "# {Rails. root}/tmp/txt_file.txt "csv_file_path = ENV ['csv _ file_path '] |" # {Rails. root}/tm P/csv_file.csv "File. new (csv_file_path) if FileTest: exists? (Csv_file_path) CSV. open (csv_file_path, 'w') do | data