Common tools for converting txt to csv

Source: Internet
Author: User

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 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.