<p>You could use the following perl one-liner, however if genome you are using contains more than one chromosome you need to figure out which lines get which chromosome chr1, chr2. If it's single chrosome like E.coli, usually name of chromosome is &quot;chr&quot;.</p>
<pre><code>perl -npe &quot;s/(.*)/chr\t\1/&quot; dat.tsv
</code></pre>

CC BY-SA 4.0
2024-03-26T02:54:04.333Z
2024-03-26T02:54:04.333Z
Supertech
<p>I appreciate your responses.</p>
<p>Using the R <code>dplyr</code> package after using <code>bedtools</code>, I was able to deal with this problem.
Using the <code>makewindows</code> function from <code>bedtool</code>, I first obtain a 100 bp window.</p>
<p>The <code>full_join</code> function from the <code>dplyr</code> R package then allows me to obtain a satisfactory result.</p>
<p>I was looking for a script that only uses bash.</p>

CC BY-SA 4.0
2024-03-26T04:56:06.043Z
2024-03-26T04:56:06.043Z
Deb
<p>I have some bed alike files but don't have <code>chr</code> term in the fisrt column, that I want to add <code>chr</code> and its corresponding chromosome number, I'm wondering how can I do that in bash!</p>
<pre><code>head dat.tsv
9901    10000   0.186130156985236
10001   10100   244.668091357092
10101   10200   367.420929888855
10201   10300   179.801731647738
10301   10400   141.551984387272
10401   10500   92.5066880216621
10501   10600   92.3205578646769
10601   10700   127.96448292735
10701   10800   74.6381929510795
10801   10900   62.6327978255318
</code></pre>

CC BY-SA 4.0
2024-03-24T10:52:53.647Z
Thanks for including an input file. Please show what you would like the output to look like after the `chr` term has been correctly added.
gringer
CC BY-SA 4.0
2024-03-25T16:40:29.427Z
I think the biggest problem is that it's not clear how you/we would know what chromosome numbers go with each row.
YogiOnBioinformatics
<bash><bed><tsv>
How to add corresponding "chr" before location (start, end) of bed alike file?
# How to add corresponding "chr" before location (start, end) of bed alike file?

(Asked by: username_0 on 2024-03-24)

I have some bed alike files but don't have chr term in the fisrt column, that I want to add chr and its corresponding chromosome number, I'm wondering how can I do that in bash!
head dat.tsv
9901    10000   0.186130156985236
10001   10100   244.668091357092
10101   10200   367.420929888855
10201   10300   179.801731647738
10301   10400   141.551984387272
10401   10500   92.5066880216621
10501   10600   92.3205578646769
10601   10700   127.96448292735
10701   10800   74.6381929510795
10801   10900   62.6327978255318

**Tags:** bash, bed, tsv
> **Comments:**
> **username_1**: Thanks for including an input file. Please show what you would like the output to look like after the `chr` term has been correctly added.  
> **username_2**: I think the biggest problem is that it's not clear how you/we would know what chromosome numbers go with each row.  

---

## 2 answers

### Answer by username_3 on 2024-03-26. Score: 1

You could use the following perl one-liner, however if genome you are using contains more than one chromosome you need to figure out which lines get which chromosome chr1, chr2. If it's single chrosome like E.coli, usually name of chromosome is "chr".
perl -npe "s/(.*)/chr\t\1/" dat.tsv


---

### Answer by username_0 on 2024-03-26. Score: -1

I appreciate your responses.

Using the R `dplyr` package after using `bedtools`, I was able to deal with this problem.
Using the `makewindows` function from `bedtool`, I first obtain a 100 bp window.

The `full_join` function from the `dplyr` R package then allows me to obtain a satisfactory result.

I was looking for a script that only uses bash.


---

