This is a test version of Biostars. For the public version, visit https://www.biostars.org.
append to column in bedfile

I have a bed file that looks like this:

scaffold1        206     262   loc.00001       +       .
scaffold1        749     1391  loc.00001       +       .
scaffold1        1549    1595  loc.00001       +       .
scaffold1        2090    2657  loc.00001       +       .
scaffold1        3013    3065  loc.00001       +       .
scaffold1        3315    3371  loc.00001       +       .

I wish to append the transcript id's in linux with a peak id so that it looks like this:

scaffold1        206     262   loc.00001_peak1        +       .
scaffold1        749     1391  loc.00001_peak2        +       .
scaffold1        1549    1595  loc.00001_peak3        +       .
scaffold1        2090    2657  loc.00001_peak4        +       .
scaffold1        3013    3065  loc.00001_peak5        +       .
scaffold1        3315    3371  loc.00001_peak6        +       .

I have used the following command to add peak_ids to the file. I just don't know how to conjugate it to the column itself.

awk '{printf "peak_%d\t%s\n", NR, $0}' int.bed > int.new.bed
bed

1 answer

awk 'BEGIN{OFS="\t"}{$4=sprintf("%s_peak%i",$4, NR); print}' input.bed > output.bed

Log in to answer this question.