# transpose
Command line tool for transforming row/column formatted textual data.
Often you have data formatted in rows and columns in some way, this tool
allows one to specify how your data in each line is organised in columns.
`transpose` can transform the matrix formed by the columns and rows in
several ways. You can transpose, rotate by multiples of 45 or 90 degrees.
Or flip the data vertically, or horizontally.
The default action is to transpose ( swap rows with columns ).
Several ways of defining what consists a 'column':
* fixed width columns.
* using a separator pattern, default: '`\t|,\s*| +`'
- TAB or COMMA followed by optional whitespace or SPACES
* by a column pattern, example: '`\s+\w+`'
* separator with quoted strings, often used in CSV files.
In the output the separator is either the single character separator specified with the `-t` option,
or, when the separator is a pattern, a TAB charater is used.
Data is either read from stdin, or from files specified on the commandline.
# Usage
usage: transpose.py [-h] [--test] [--verbose] [-t SEPARATOR] [-p PATTERN]
[-w WIDTH] [-l] [-a] [-q] [-Q] [--yflip] [--xflip]
[--rotate DEG] [+180] [+90] [-90] [+45] [-45] [--skew]
[DAT [DAT ...]]
transform a matrix, default: transpose
positional arguments:
DAT
optional arguments:
-h, --help show this help message and exit
--test run unittest
--verbose, -v
-t SEPARATOR, --separator SEPARATOR
column separator
-p PATTERN, --pattern PATTERN
column pattern, example: \s+\w+
-w WIDTH, --width WIDTH
Fixed width columns, alow multiple widths. Either a
comma separated list of widths, with the last value
taken for the remaining columns. ( 5,1,1,10 )
Optionally a width can be prefixed with a column
number followed by a colon. ( 5:1,7:1,8 )
-l, --keepspaces Leading whitespace is relevant
-q, --quoted Quoted strings with C style escapes ( using backslash
)in columns.
-Q, --dquoted Quoted strings with SQL style escapes ( using repeated
quotes ) in columns.
--yflip, -y reverse each line
--xflip, -x, --tac like "tac", output lines in reverse order
--rotate DEG Rotate by multiple of 45 degrees
+180, -180 rotate by 180 degrees
+90 rotate by 90 degrees counter-clockwise
-90 rotate by 90 degrees clockwise
+45 rotate by 45 degrees counter-clockwise
-45 rotate by 45 degrees clockwise
--skew rotate by 45 degrees clockwise, but de-indent
Specify negative numbers using: --rotate=-45
# Example
## split the output of `ls` into columns, and transpose:
ls -al | transpose -w 10,5,6,7,7,12
NOTE: this depends on the actual rendering by `ls`, column widths may vary.
Alternatively, you could split the output of `ls` into columns using:
ls -al | transpose -p "\S+\s*" -t,
## Swap columns and rows:
cat <<__EOF__ | transpose
a b c
d e f
__EOF__
Will result in:
a d
b e
c f
## Rotate by 45 degrees
cat <<__EOF__ | transpose -45
a b c
d e f
g h i
__EOF__
Results in:
a
d b
g e c
h f
i
## reverse column order
cat <<__EOF__ | transpose -y
a b c
d e f
__EOF__
Will result in:
c b a
f e d
## reverse a line
transpose -y -w 1
transpose -y -p .
## reverse words in a line
transpose -y -t " "
## reverse a list of lines
Like `tac`:
transpose -x
# TODO
* Handle multiline quoted values.
* Add option to specify regex extracting columns from entire line.
* Add option to left/right-align columns in the output.
* Add option to retain separators with their column value.
- you can already kind of do this using the --pattern option.
* I thought about adding options to change the way values are quoted, and separated,
now i think that is better left to a different tool. So for now i will just leave
the quoting and escaping intact, like it is.
* Add option to specify an output separator.
# Author
Willem Hengeveld <itsme@xs4all.nl>
没有合适的资源?快使用搜索试试~ 我知道了~
PyPI 官网下载 | text-transpose-1.0.0.tar.gz
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 181 浏览量
2022-01-16
21:37:31
上传
评论
收藏 7KB GZ 举报
温馨提示
资源来自pypi官网。 资源全名:text-transpose-1.0.0.tar.gz
资源推荐
资源详情
资源评论
收起资源包目录
text-transpose-1.0.0.tar.gz (10个子文件)
text-transpose-1.0.0
setup.py 1KB
text_transpose.egg-info
top_level.txt 10B
SOURCES.txt 224B
PKG-INFO 2KB
entry_points.txt 46B
dependency_links.txt 1B
transpose.py 14KB
setup.cfg 38B
README.md 5KB
PKG-INFO 2KB
共 10 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功