Align rows in text file with command line -
i have data in text file data rows repeated after several columns , each new block shares first column of row labels. i'd use command line align rows single table.
the data text file looks like:
values samplea sampleb samplec value1 1.00 2.00 3.00 value2 3.00 2.00 1.00 value3 2.00 1.00 3.00 values sampled samplee samplef value1 1.00 2.00 3.00 value2 3.00 2.00 1.00 value3 2.00 1.00 3.00
and i'd resulting file like:
values samplea sampleb samplec sampled samplee samplef value1 1.00 2.00 3.00 1.00 2.00 3.00 value2 3.00 2.00 1.00 3.00 2.00 1.00 value3 2.00 1.00 3.00 2.00 1.00 3.00
this solution creates lots of temp files, cleans after.
# put each paragraph it's own file: awk -v rs= '{print > sprintf("%s_%06d", filename, nr)}' data.txt # now, join them, , align columns join data.txt_* | column -t | tee data.txt.joined # , cleanup temp files rm data.txt_*
verify afterwards with: wc -l data.txt data.txt.joined
Comments
Post a Comment