# 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>
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- 模块化多电平流器仿真MMC Matlab-Simulink N=22 采用最近电平逼近调制 功率外环 电流内环双闭环控制 电流内环采用PI+前馈解耦,电容电压排序, 并网后可以得到对称的三相电压和三相
- 赛灵思FPGA匹配CMV2000,图纸资料齐全,提供软件代码,PCB等,软件代码附说明,方便读懂
- 171-西门子1200PLC机器人控制程序模板,程序模板清晰明了,容易看懂,有注释,硬件采用1214CPU,触摸屏采用KTP700系列 打开软件采用博图V15.1及以上
- 西南科技大学密码学希尔密码实验
- comsol激光模型整理合集,可提供自己讲解的视频,说明每步操作意义 1.图1-3为激光热应力模型,采用固体力学、固体传热研究激光焊接下材料的应力及温度变化情况,研究指定点的温度随时间的变化情况
- GB28181 webrtc视频监控 摄像机国标对接源码源代码程序 C C++
- 西南科技大学密码学RSA实验
- simulink三相逆变电路的仿真模型 PWM三相逆变电路,基于Matalab2018a
- 西南科技大学密码学AES实验
- 光伏控制器,光伏三相并网仿真 带说明文件,参考文献 模型内容: 1.光伏+MPPT控制+两级式并网逆变器(boost+三相桥式逆变) 2.坐标变+锁相环+dq功率控制+解耦控制+电流内环电压外环控
- 判断闰年平年.html
- 算数优化算法AOA优化LSTM做多特征输入单输出的二分类及多分类模型 程序内注释详细,直接替数据就可以用 程序语言为matlab 程序可出分类效果图,迭代优化图,混淆矩阵图具体效果如下所示
- 锂电池分选机 欧姆龙NJ501-1500,威伦通触摸屏 锂离子电池自动分选机 电压测试,日置电阻表测试,基恩士测厚仪 国际IEC 61131标准编程模式,设备涵盖伺服运动控制,高创直线电机DD
- Labview示波器源代码,所有信号由内部产生,信号类型可以自己设置,带保存和回放功能,是学习和理解示波器及labview重要手段
- Maxwell 电机设计,motorCAD电机设计,永磁同步电机,开关磁阻电机,直流电机,异步电机仿真
- 大数据基础+Hadoop+HDFS+HBase+Hive+MapReduce+Spark
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈