Answers.Body: <p>Assuming that the third line is the continuation of the second line. Here's a one (long) liner:</p>
  <pre class="lang-bash prettyprint-override"><code>cat &lt;( \
        paste -d '\t' \
           &lt;(echo &quot;Id&quot;) \
           &lt;(head -1 test.tsv \
        | cut -f5- \
        | sed -e '$s/\[[[:digit:]]\+\]//g; s/_HG[[:digit:]]\+//g') ) \
      &lt;( \
        paste -d '\t' \
          &lt;(awk 'NR&gt;1 {print $1&quot;_&quot;$2&quot;_&quot;$3&quot;_&quot;$4&quot;_b37&quot;}' test.tsv) \
          &lt;(awk 'NR&gt;1 {print $0}' test.tsv | cut -f5- | sed 's/\.[[:digit:]]\+//g')) \
  &gt; output.tsv
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-18T18:33:02.913Z
Answers.Text: Yes, this code worked for my input data.
Answers.UserDisplayName: Rhea Bedi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-16T00:35:09.903Z
Answers.LastActivityDate: 2022-01-16T00:35:09.903Z
Answers.UserDisplayName: user324810
Body: <p><a href="https://i.sstatic.net/pVxA6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pVxA6.png" alt="This is how my input file looks like. I am not able to show the header of the file so I am showing the one with 22_160549_T_C_b37 one" /></a><a href="https://i.sstatic.net/ij2dh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ij2dh.png" alt="This is how the output file should look like. This is not mine. But a test data image" /></a>I have an imputed dosage for chr 22 file. its content is:</p>
  <pre><code>#[1]CHROM       [2]POS  [3]REF  [4]ALT  [5]HG00096_HG00096      [6]HG00097_HG00097      [7]HG00099_HG00099      [8]HG00100_HG00100     
  22      16051249        T       C       0.0     1.0     1.0     0.0    0.0     1.0     0.0     0.0     1.0     0.0     
  </code></pre>
  <p>I want to remove <code>[]</code> and remove anything coming after <code>_</code> from this file as well as instead of separate <code>22</code> <code>16051249</code> <code>T</code> and <code>C</code> i want to write:</p>
  <pre><code>22_16051249_T_C_b37
  </code></pre>
  <p>So the final file should look like:</p>
  <pre><code>Id      HG00096 HG00097 HG00099 HG00100 
  22_16051249_T_C_b37     0       1       1       0       1       0       0       1       0       
  </code></pre>
  <p>Can anyone please help me out with this.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-15T21:53:18.063Z
Comments.Text: Is your file tab-separated?
Comments.UserDisplayName: user324810
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-15T22:03:55.987Z
Comments.Text: It's better to ask here question regarding specific steps you are struggling with. You seem to want 1, rename header (which frankly I don't know why you would not do in a text editor if you have just one file) 2, merge some columns 3, add there "b37", which I am not even sure where it comes from. I am sure 1 you manage on your own, 2 might be sneakier, however it already is answered many times on stack exchange (if you can't find one it's fine, just post it), 3 you got to explain better. It's not clear at all. Here we like specific questions.
Comments.UserDisplayName: Kamil S Jaron
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-15T22:06:26.473Z
Comments.Text: This is what i have tried so far. I tried to remove the brackets using this command and it worked.
  
  `sed -e 's/[[^][]*]//g' `
  
  And for adding the 22_1605149_T_C I did this:
  
  `awk '{ID=$1""$2" "$3""$4" " +b37; print ID}' genotype.chr22_1.txt > genotype.chr22_2.txt`
  
  But it just gives me a separate file with these values and not want I want. I tried to join the columns using R but it doesn't generate a separate column. the command used is:
  
  `genotype_chr22_1$ID <- paste(genotype_chr22_1$CHROM, genotype_chr22_1$POS,genotype_chr22_1$REF, genotype_chr22_1$ALT, sep = "_")`
Comments.UserDisplayName: Rhea Bedi
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-15T22:25:41.663Z
Comments.Text: @RheaBedi I can't really understand the given content of your example. On the first line is the header with 8 columns of which the first 4 will be merged into 1 called `Id`. On the second line, you have 8 columns, and like the previous, I can understand it will become `22_16051249_T_C_b37`. But what about the third line? And how is that in your final file, the first line has 5 columns while the second line has more?
Comments.UserDisplayName: user324810
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-15T23:09:39.077Z
Comments.Text: The third line would continue with the values. The first column represent ID and the rest of the columns are sample IDs which represent HG0096. the file would have 2504 sample IDs. and each first row would represent 22_160549_T_C_b37 and their corresponding values 0,1 or 2
Comments.UserDisplayName: Rhea Bedi
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-15T23:55:12.907Z
Comments.Text: Do you mean that the third line is a continuation of the second line? like there's no newline right?
Comments.UserDisplayName: user324810
Tags: <file-formats>
Title: How to format my file using linux tools?
ThreadText: # How to format my file using linux tools?
  
  (Asked by: username_0 on 2022-01-14)
  
  [![This is how my input file looks like. I am not able to show the header of the file so I am showing the one with 22_160549_T_C_b37 one](https://i.sstatic.net/pVxA6.png)](https://i.sstatic.net/pVxA6.png)[![This is how the output file should look like. This is not mine. But a test data image](https://i.sstatic.net/ij2dh.png)](https://i.sstatic.net/ij2dh.png)I have an imputed dosage for chr 22 file. its content is:
  
  ```
  #[1]CHROM       [2]POS  [3]REF  [4]ALT  [5]HG00096_HG00096      [6]HG00097_HG00097      [7]HG00099_HG00099      [8]HG00100_HG00100     
  22      16051249        T       C       0.0     1.0     1.0     0.0    0.0     1.0     0.0     0.0     1.0     0.0     
  
  ```
  
  I want to remove `[]` and remove anything coming after `_` from this file as well as instead of separate `22` `16051249` `T` and `C` i want to write:
  
  ```
  22_16051249_T_C_b37
  
  ```
  
  So the final file should look like:
  
  ```
  Id      HG00096 HG00097 HG00099 HG00100 
  22_16051249_T_C_b37     0       1       1       0       1       0       0       1       0       
  
  ```
  
  Can anyone please help me out with this.
  
  **Tags:** file-formats
  
  > **Comments:**
  > **username_1**: Is your file tab-separated?  
  > **username_2**: It's better to ask here question regarding specific steps you are struggling with. You seem to want 1, rename header (which frankly I don't know why you would not do in a text editor if you have just one file) 2, merge some columns 3, add there "b37", which I am not even sure where it comes from. I am sure 1 you manage on your own, 2 might be sneakier, however it already is answered many times on stack exchange (if you can't find one it's fine, just post it), 3 you got to explain better. It's not clear at all. Here we like specific questions.  
  > **username_0**: This is what i have tried so far. I tried to remove the brackets using this command and it worked.  `sed -e 's/[[^][]*]//g' `  And for adding the 22_1605149_T_C I did this:  `awk '{ID=$1""$2" "$3""$4" " +b37; print ID}' genotype.chr22_1.txt > genotype.chr22_2.txt`  But it just gives me a separate file with these values and not want I want. I tried to join the columns using R but it doesn't generate a separate column. the command used is:  `genotype_chr22_1$ID <- paste(genotype_chr22_1$CHROM, genotype_chr22_1$POS,genotype_chr22_1$REF, genotype_chr22_1$ALT, sep = "_")`  
  > **username_1**: @username_0 I can't really understand the given content of your example. On the first line is the header with 8 columns of which the first 4 will be merged into 1 called `Id`. On the second line, you have 8 columns, and like the previous, I can understand it will become `22_16051249_T_C_b37`. But what about the third line? And how is that in your final file, the first line has 5 columns while the second line has more?  
  > **username_0**: The third line would continue with the values. The first column represent ID and the rest of the columns are sample IDs which represent HG0096. the file would have 2504 sample IDs. and each first row would represent 22_160549_T_C_b37 and their corresponding values 0,1 or 2  
  > **username_1**: Do you mean that the third line is a continuation of the second line? like there's no newline right?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-16. Score: 1 | Accepted answer
  
  Assuming that the third line is the continuation of the second line. Here's a one (long) liner:
  
  ```bash
  cat <( \
        paste -d '\t' \
           <(echo "Id") \
           <(head -1 test.tsv \
        | cut -f5- \
        | sed -e '$s/\[[[:digit:]]\+\]//g; s/_HG[[:digit:]]\+//g') ) \
      <( \
        paste -d '\t' \
          <(awk 'NR>1 {print $1"_"$2"_"$3"_"$4"_b37"}' test.tsv) \
          <(awk 'NR>1 {print $0}' test.tsv | cut -f5- | sed 's/\.[[:digit:]]\+//g')) \
  > output.tsv
  
  ```
  
  > **Comments:**
  > **username_0**: Yes, this code worked for my input data.  
  
  ---
  
  