thank you very much
Hello, I have a data file with 4 values in same column. How to split each column in 4 labelled columns v1, v2,v3 and v4 with bash or R or python ?
example of my file :
Barcode "FD1133" "FD1138"
102 "-0.0570 0.0113 1.035 0.061" " -0.3631 0.0065 0.842 0.045"
104 "-0.0334 1.0000 0.013 0.813" "-0.0604 0.9639 0.052 0.764"
Thank you very much
2 answers
Assuming that your data is saved in a file named file.txt:
echo "v1\tv2\tv3\tv4" > FD1133_columns.txt
echo "v1\tv2\tv3\tv4" > FD1138_columns.txt
grep -v Barcode file.txt | awk -F '\"' '{print $2}' | awk '{print $1"\t"$2"\t"$3"\t"$4}' >> FD1133_columns.txt
grep -v Barcode file.txt | awk -F '\"' '{print $4}' | awk '{print $1"\t"$2"\t"$3"\t"$4}' >> FD1138_columns.txt
If an answer was helpful, you should upvote it; if the answer resolved your question, you should mark it as accepted. You can accept more than one answer if they work. This will help future users that might find this post find the right answer.

Using the separate function from tidyr, assuming your data.frame is named df.
if(!require("tidyr")) install.packages("tidyr")
library(tidyr)
df <- separate(df, col = "FD1133", into = c("col_1","col_2","col_3","col_4"), sep = " ")
Do this for every column you want to split (just change the col = part of the code.)
thank you very much
separate is part of tidyr. Why install the whole tidyverse set of packages? Plus, OP wants v[0-9]+ column names, not col_[0-9]+ column names.
Loading up tidyverse is my personal preference. However, I edited my initial point in case OP wants to know the exact package this function is coming from. As for the latter part of your question, I would hope OP would understand from my code that they can name the column to whatever they desire.
I feel like it's an unnecessary twist to give the exact code that OP needs with one simple needless difference. We should either give pseudocode/pointers or exact code with logic-based missing steps or exact functioning code. Exact code with a radnom semantic difference achieves next to nothing wrt educating the user.
Yes, I think you’re right here. I think as we progress into our programming, we tend to overlook things like this. I’ll keep this logic as I move forward with future response.
Log in to answer this question.
melania 2282 : Please don't delete posts once they have received an answer or comments.
if you can handle headers, try
column -tHow does this help OP?
columnformats content for display, it does nothing to split or manipulate content in any way that awk can.