<p>I am really curious what software or piece of code gave you this one-line data. I would think twice before using a tool giving such output. Anyway, I think regular expressions is the way to go in this case (this solution uses <code>R</code>):</p>

<pre><code>library(stringr)

text &lt;- "#Uploaded variation   #Uploaded_variation 1 883477 G T 1_883477_G/TPRDM16 1 3125744 A G 1_3125744_A/GPRDM16"

my_pattern &lt;- "[0-9]+\\s[0-9]+\\s[ATGC]+\\s[ATGC]+\\s[0-9]+_[0-9]+_[ATGC]+\\/[0-9A-Z]+"

info_as_list &lt;- str_extract_all(text,
                                pattern = my_pattern) %&gt;% unlist()

info_as_list &lt;- sub("/",
                    " ",
                    info_as_list)

info_as_list &lt;- str_split(info_as_list, " ")

as.data.frame(Reduce(rbind, info_as_list))
</code></pre>

<p>This is the output, I guess the rowname "init" comes from <code>Reduce()</code>:</p>

<pre><code>     V1      V2 V3 V4          V5      V6
init  1  883477  G  T  1_883477_G TPRDM16
      1 3125744  A  G 1_3125744_A GPRDM16
</code></pre>

<p>Here is what the regular expression does, you might need to alter this based on your data:</p>

<pre><code>[0-9]+\\s       :   start position
[0-9]+\\s       :   end position
[ATGC]+\\s      :   ref nucleotide(s)
[ATGC]+\\s      :   alternate nucleotide(s)
[0-9]+          :   start
_               :   underscore
[0-9]+          :   end
_               :   underscore
[ATGC]+         :   ref
\\/             :   slash
[0-9A-Z]+       :   gene symbol
</code></pre>

<p><code>+</code> means one or more of the preceding and <code>R</code> uses two backslashes, <code>\\</code>, as escape characters.</p>

CC BY-SA 4.0
2020-04-15T20:54:39.563Z
Sorry @haci everything is fine except for your are adding alternative allele to the start of gene like TPRDM16 while in column V5 I need 1_883477_G/T and in column V6 I need gene name which is PRDM16.
Zizogolu
CC BY-SA 4.0
2020-04-15T21:02:29.073Z
You can alter column 5 by pasting it with column 4. Use `paste()` with `sep="/"`.
haci
CC BY-SA 4.0
2020-04-15T21:05:16.543Z
I don't want to paste column V5 to V6, they are independent columns. In column V6 I need only PRDM16 because this is a gene symbol and in column V5 I need a combination of columns V1 to V4 as 1_883477_G/T. Your kindly code pastes a part of column V5 to V6 which is undesired. If I paste column V5 to V4 I also have to remove the first character of column V6 which is too confusing for me
Zizogolu
CC BY-SA 4.0
2020-04-16T08:28:01.263Z
@Exhausted, this is not a code writing service as @Michael stated above. We cannot give you completely working code but can only point you to the right direction. If you would have googled "R remove the first character of a string", you would find out `substring()` is the way to go to "clean" the extra character in your "gene name" column: `df$V6 <- substring(df$V6,2)`
haci
CC BY-SA 4.0
2020-04-15T20:37:34.917Z
2020-04-16T08:40:20.993Z
2020-04-16T08:40:20.993Z
haci
<p>I have this data all is one line even gene from first sample joined the second one while I want this data column wise each field separated like I have provided </p>

<pre><code>#Uploaded variation   #Uploaded_variation 1 883477 G T 1_883477_G/TPRDM16 1 3125744 A G 1_3125744_A/GPRDM16
</code></pre>

<p>But I want</p>

<pre><code>         V1     V2  V3      V4  V5  V6
1_883477_G/T    1   883477  G   T   PRDM16
1_3125744_A/G   1   3125744 A   G   PRDM16
</code></pre>

CC BY-SA 4.0
2020-04-15T14:45:12.603Z
Hi @Exhausted, this a similar style of question to your Google heatmap question, in that you posted the input and output you wanted and then requested all the intervening code. Could post the code you have tried so far in line with the sites requirements? Please note, I didn't downvote you, but whoever did downvoted you because of your question format. In summary, Bioinfo SE is not a code writing service.
M__
CC BY-SA 4.0
2020-04-15T16:26:36.973Z
Are you sure it's one line? If you're writing a shell script, make sure you quote the variable: `echo "$data"`  and not `echo $data`
glenn jackman
CC BY-SA 4.0
2020-04-16T12:59:24.777Z
Yes you right :( I am really not happy with this even I am suffering from my attitude than the community do
Zizogolu
CC BY-SA 4.0
2020-04-16T13:52:09.327Z
I agree with the other commentators, but wanted to add that only the secondary purpose of Stack Exchange sites is to help the question asker. The primary purpose is actually to create a useful repository of questions and answers for the whole community. Unfortunately, your questions are not useful for others and titles like "How I format this data" are way too vague. Don't worry though, you can learn from this and ask better questions in the future :)
Chris_Rands
<awk>
How I reformat this data
# How I reformat this data

(Asked by: username_0 on 2020-04-15)

I have this data all is one line even gene from first sample joined the second one while I want this data column wise each field separated like I have provided 
#Uploaded variation   #Uploaded_variation 1 883477 G T 1_883477_G/TPRDM16 1 3125744 A G 1_3125744_A/GPRDM16

But I want
         V1     V2  V3      V4  V5  V6
1_883477_G/T    1   883477  G   T   PRDM16
1_3125744_A/G   1   3125744 A   G   PRDM16

**Tags:** awk
> **Comments:**
> **username_1**: Hi @Exhausted, this a similar style of question to your Google heatmap question, in that you posted the input and output you wanted and then requested all the intervening code. Could post the code you have tried so far in line with the sites requirements? Please note, I didn't downvote you, but whoever did downvoted you because of your question format. In summary, Bioinfo SE is not a code writing service.  
> **username_2**: Are you sure it's one line? If you're writing a shell script, make sure you quote the variable: `echo "$data"`  and not `echo $data`  
> **username_0**: Yes you right :( I am really not happy with this even I am suffering from my attitude than the community do  
> **username_3**: I agree with the other commentators, but wanted to add that only the secondary purpose of Stack Exchange sites is to help the question asker. The primary purpose is actually to create a useful repository of questions and answers for the whole community. Unfortunately, your questions are not useful for others and titles like "How I format this data" are way too vague. Don't worry though, you can learn from this and ask better questions in the future :)  

---

## 1 answers

### Answer by username_4 on 2020-04-15. Score: 1 | Accepted answer

I am really curious what software or piece of code gave you this one-line data. I would think twice before using a tool giving such output. Anyway, I think regular expressions is the way to go in this case (this solution uses R):
library(stringr)

text <- "#Uploaded variation   #Uploaded_variation 1 883477 G T 1_883477_G/TPRDM16 1 3125744 A G 1_3125744_A/GPRDM16"

my_pattern <- "[0-9]+\\s[0-9]+\\s[ATGC]+\\s[ATGC]+\\s[0-9]+_[0-9]+_[ATGC]+\\/[0-9A-Z]+"

info_as_list <- str_extract_all(text,
                                pattern = my_pattern) %>% unlist()

info_as_list <- sub("/",
                    " ",
                    info_as_list)

info_as_list <- str_split(info_as_list, " ")

as.data.frame(Reduce(rbind, info_as_list))

This is the output, I guess the rowname "init" comes from Reduce():
     V1      V2 V3 V4          V5      V6
init  1  883477  G  T  1_883477_G TPRDM16
      1 3125744  A  G 1_3125744_A GPRDM16

Here is what the regular expression does, you might need to alter this based on your data:
[0-9]+\\s       :   start position
[0-9]+\\s       :   end position
[ATGC]+\\s      :   ref nucleotide(s)
[ATGC]+\\s      :   alternate nucleotide(s)
[0-9]+          :   start
_               :   underscore
[0-9]+          :   end
_               :   underscore
[ATGC]+         :   ref
\\/             :   slash
[0-9A-Z]+       :   gene symbol

+ means one or more of the preceding and R uses two backslashes, \\, as escape characters.

> **Comments:**
> **username_0**: Sorry @haci everything is fine except for your are adding alternative allele to the start of gene like TPRDM16 while in column V5 I need 1_883477_G/T and in column V6 I need gene name which is PRDM16.  
> **username_4**: You can alter column 5 by pasting it with column 4. Use `paste()` with `sep="/"`.  
> **username_0**: I don't want to paste column V5 to V6, they are independent columns. In column V6 I need only PRDM16 because this is a gene symbol and in column V5 I need a combination of columns V1 to V4 as 1_883477_G/T. Your kindly code pastes a part of column V5 to V6 which is undesired. If I paste column V5 to V4 I also have to remove the first character of column V6 which is too confusing for me  
> **username_4**: @Exhausted, this is not a code writing service as @Michael stated above. We cannot give you completely working code but can only point you to the right direction. If you would have googled "R remove the first character of a string", you would find out `substring()` is the way to go to "clean" the extra character in your "gene name" column: `df$V6 <- substring(df$V6,2)`  

---

