This is a test version of Biostars. For the public version, visit https://www.biostars.org.
[Resolved] Adding a unique ID column to a bed file

Hello

I have this kind of bed file :

chr1    39630894    39631095    +
chr1    158409432    158409633    +
chr10    75600726    75600927    +
chr13    10359410    10359611    +
chr13    10448814    10449015    +
chr13    64450832    64451033    +
chr14    110276447    110276648    +

I need to add a first column with a unique identifier in order to annotate this file using Homer.

Adding the column is not the problem, but I don't know how to create a column with a unique id such as peaks_X with X being the line number of my bed file for example.

I thought of using a for loop, but it's not that easy in unix. I can retrieve the number of line with wc -l, but I don't know how to set the condition: add from 1 to wc -l file.bed

Anyone see an easy way to do this with unix, perl, or anything ?

Thank you!

bed data-managment

1 answer

Found solution alone:

awk '{printf "peak_%d\t%s\n", NR, $0}' < test.bed

Log in to answer this question.