# delimited2fixedwidth
Convert files from delimited (e.g. CSV) to fixed width format
[![Latest release on GitHub](https://img.shields.io/github/v/release/e2jk/delimited2fixedwidth)](https://github.com/e2jk/delimited2fixedwidth/releases/latest)
[![Latest release on PyPI](https://img.shields.io/pypi/v/delimited2fixedwidth)](https://pypi.org/project/delimited2fixedwidth/)
[![Build Status](https://travis-ci.com/e2jk/delimited2fixedwidth.svg?branch=master)](https://travis-ci.com/e2jk/delimited2fixedwidth)
[![codecov](https://codecov.io/gh/e2jk/delimited2fixedwidth/branch/master/graph/badge.svg)](https://codecov.io/gh/e2jk/delimited2fixedwidth)
[![GitHub last commit](https://img.shields.io/github/last-commit/e2jk/delimited2fixedwidth.svg)](https://github.com/e2jk/delimited2fixedwidth/commits/master)
[![License](https://img.shields.io/github/license/e2jk/delimited2fixedwidth)](../../tree/master/LICENSE)
How to run the program
======================
How to install the program
--------------------------
For Linux and Windows, download the latest version from [here](https://github.com/e2jk/delimited2fixedwidth/releases/latest) (look under the "Assets" section) and run it on your system, no need to install anything else.
The program can also be installed from the Python Package Index:
```
pip install delimited2fixedwidth
```
See below [how to install from source](#how-to-install-from-source).
Configuration file
------------------
In order for the program to know how to transform your delimited file into a fixed-width file, you will need to provide a configuration file describing the length and type of values expected for your output file.
An example configuration file can be found at
[`tests/sample_files/configuration1.xlsx`](../../tree/master/tests/sample_files/configuration1.xlsx)
A configuration file is a simple Excel `.xlsx` file in which each row represents a single field expected in the output file (the fixed-width file), and at least these 3 column headers, i.e. the first line in your Excel file:
* Length
* Output format
* Skip field
The **Length** value is self-explanatory: it represents how long the field will be in the generated fixed-width file. If the value in the input file is shorter than this defined length, it will be padded with `0`s or spaces, depending on the type of Output format (see next section).
The **Output format** defines how the input value must be treated and transformed. The following values are supported:
* `Integer`
* A numeric value that gets padded with `0`s added to the left
* Example: "`123`" becomes "`000123`" if a length of 6 is defined
* `Decimal`
* Decimal numbers get sent as "cents" instead of "dollars", rounded to the nearest cent. (yeah, weird explanation -- better have a look at the example...). Also padded with `0`s added to the left.
* Example: "`123.458`" becomes "`00012346`" if a length of 8 is defined
* `Keep numeric`
* strips all non-numeric characters from an input value and treats the remaining value as `Integer`
* Example: "`1-2.3a`" becomes "`000123`" if a length of 6 is defined
* Date
* A date to be converted from one format to another. The input value can be sent with either Day or Month as first element or as ISO format YYYYMMDD, and with a slash, dash, dot or no separator. When there is a separator defined, the day and month can omit the leading 0, if need be. See at the top of the [`test_main.py` file](https://github.com/e2jk/delimited2fixedwidth/blob/master/tests/test_main.py#L37) for the full list of supported codes.
* Examples:
* "`21/06/2020`" becomes "`20200621`" with a format of `Date (DD/MM/YYYY to YYYYMMDD)` and a length of 8
* "`6-21-2020`" becomes "`20200621`" with a format of `Date (MM-DD-YYYY to YYYYMMDD)` and a length of 8
* "`21062020`" becomes "`20200621`" with a format of `Date (DDMMYYYY to YYYYMMDD)` and a length of 8
* "`6.21.2020`" becomes "`21/06/2020`" with a format of `Date (MM.DD.YYYY to DD/MM/YYYY)` and a length of 10
* `Time`
* A time sent as hour:minutes (with or without colon in the input data) will be sent out without the colon
* Example: "`20:06`" becomes "`2006`" if a length of 4 is defined
* `Text`
* The value gets sent without format changes (such as those outlined above for date and time), with spaces added at the end, on the right of the string
* Example: "`Hello`" becomes "<code>Hello </code>" if a length of 10 is defined
Finally, setting the value of the **Skip field** column to "`True`" allows to send a field as blank in the output file, respecting the field size and padding type: `0`s or spaces depending on the defined output format.
Running the program
-------------------
Open a Command Line window `cmd` and indicate your input file name, output file name and configuration file to use. You can additionally indicate if your input file uses a specific field separator (default is `,`), textual field wrapper (default is `"`), or if you want to skip a specific number of header or footer files from your input file.
See the [Program help information](#program-help-information) section below for details on how to populate these arguments.
An example run of the program could look like this:
```
delimited2fixedwidth.exe --input data\input_file.txt --config data\configuration_file.xlsx --output data\output_file.txt --delimiter "^" --skip-header 1 --skip-footer 1
```
Program help information
------------------------
```
usage: delimited2fixedwidth.py [-h] [--version] -o OUTPUT [-x] -i INPUT -c CONFIG [-dl DELIMITER] [-q QUOTECHAR]
[-sh SKIP_HEADER] [-sf SKIP_FOOTER] [-l LOCALE] [-t TRUNCATE] [-dv DIVERT] [-d] [-v]
Convert files from delimited (e.g. CSV) to fixed width format
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
-o OUTPUT, --output OUTPUT
Specify the output file
-x, --overwrite-file Allow to overwrite the output file
-i INPUT, --input INPUT
Specify the input file
-c CONFIG, --config CONFIG
Specify the configuration file
-dl DELIMITER, --delimiter DELIMITER
The field delimiter used in the input file (default ,)
-q QUOTECHAR, --quotechar QUOTECHAR
The character used to wrap textual fields in the input file (default ")
-sh SKIP_HEADER, --skip-header SKIP_HEADER
The number of header lines to skip (default 0)
-sf SKIP_FOOTER, --skip-footer SKIP_FOOTER
The number of footer lines to skip (default 0)
-l LOCALE, --locale LOCALE
Change the locale, useful to handle decimal separators
-t TRUNCATE, --truncate TRUNCATE
Comma-delimited list of field numbers for which the output will be truncated at the maximum
line length, should the input value be longer than the maximum defined field length. If not
set, a field that is too long will cause the script to stop with an error.
-dv DIVERT, --divert DIVERT
Diverts to a separate file the content from rows containing a specific value at a specific
place. The format of this parameter is "<field number>,<value to divert on>" (without quotes).
This parameter can be repeated several times to support different values or different fields.
The diverted content will be saved to a file whose name will be the output filename with
"_diverted" added before the file extension.
-d, --debug Print lots of debugging statements
-v, --verbose Be verbose
```
Development information
================
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共13个文件
txt:4个
py:4个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:delimited2fixedwidth-1.0.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
delimited2fixedwidth-1.0.7.tar.gz (13个子文件)
delimited2fixedwidth-1.0.7
delimited2fixedwidth.egg-info
PKG-INFO 15KB
requires.txt 47B
SOURCES.txt 320B
top_level.txt 21B
dependency_links.txt 1B
MANIFEST.in 14B
PKG-INFO 15KB
tests
__init__.py 0B
test_main.py 63KB
delimited2fixedwidth.py 24KB
setup.cfg 355B
setup.py 1KB
README.md 9KB
共 13 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- LS416 高性能DSP的声控处理芯片语音识别模块AD设计硬件(原理图+PCB)+L2416-M-26P模块封装库+器件手册
- 基于tensorflow实现LSTM, CNN, SVM, MLP语音情感识别源码.zip
- 基于JSP在线学生选课管理系统源码.zip
- 基于JSP在线学生信息管理系统源码.zip
- 常用DHT11 MIC SHT11 VS1838B CHT8305 MQ-3 温湿度气体等传感元件2D3D封装库.PcbLib
- 基于JSP在线新闻管理系统包含前后台源码.zip
- 基于JSP在线文具销售平台商城源码.zip
- tiamo软件教程.doc
- nvm管理Nodejs多版本工具
- Unit1Howcanwebecomegoodlearners知识点整理(良心出品必属精品).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功