This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Edit table to create start and end position of recombination rate

Hi,

I need to modify a number of very large tables. The tables contain recombination rates of each chromosome (ID) at specific positions.

The table has the structure: First column: ID; Second: Position; Third: Rate

Example input file

A 1 1.5

A 2 1.5

A 3 1.6

A 4 1.6

B 1 2.7

B 2 2.7

B 3 2.5

I would like to modify it into: First column: ID; Second: start position; Third: end position; Fourth: rate

Example output file

A 1 2 1.5

A 3 4 1.6

B 1 2 2.7

B 3 3 2.5

I usually edit my files using awk or sed, but I cannot figure out how to solve my problem. Help is much appreciated.

sed bash awk

1 answer

As a seasoned user of awk or sed, you will certainly know, that both tools process files line by line.

So if you would like to combine information that is not on the same line, you have to change that beforehand: paste - - < file.txt | awk '...'

Log in to answer this question.