Hong Zheng


Hong Zheng / 2017-08-30

There’s more than one way to do it. (TMTOWTDI)

Although this is a perl motto, it applies to R, Python, bash, whatever language you name it.

The commands I put together here are very basic data manipulating techniques. I use Linux/Bash and R a lot, but often I forget the specific syntax and have to look it up somewhere. Here is the collection of them:

Calculate the sum of one column 计算一列之和

Calculate the sum of every column 计算每列之和

Transpose (switch rows and columns) 行列转置

Subtraction of adjecent rows 邻行相减

Order according to row 行排序

Output according to column names 根据列名输出

Concatenate every two lines 每两行合并

Concatenate every three lines 每三行合并

Upper and lower case transform 大小写转换

Concatenate every line in a file

Other BASH tips

Use user-specified seperators in sort

sort -t $'\t' -k1