Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Select Columns from Structured Text Files

Python pandas

My first choice is pandas in Python. However, below are some tools for quick and dirty solutions.

q

q -t -H 'select c1, c3 from file.txt'

cut

cut -d\t -f1,3 file.txt

awk

awk -F'\t' '{print $1 "\t" $3}' file.tsv 

Note: neither cut nor awk honors escaped characters. For working on complicated structured text files, pandas in Python is a much better solution.

Comments