This is a test version of Biostars. For the public version, visit https://www.biostars.org.
split text file in multiples text files

Hello, I Have a file text that looks like this

number1.1   characters_string_1
number1.2   characters_string_2
number1.3   characters_string_3

number2.1   characters_string_1
number2.2   characters_string_2
number2.3   characters_string_3

number3.1   characters_string_1
number3.2   characters_string_2
number3.3   characters_string_3

and I would like to split this text file in multiple text files

sequence

how do expect your 'multiple text files' to look like? Each line one file? Each column one file? There are so many options...

How about

man split

?

Your question needs a lot more information. In addition, it is not obvious how this is related to bioinformatics, which is required on Biostars. Please update your question and elaborate.

What is the expected output for this file? 3 files based on blank rows? or 3 files based on first column? Please clarify.

if you want to save each line into a separate file,

cat file.txt | while read line; do echo $line > $line.txt ; done

Just a minor comment, but this will probably lead to unpleasant file names, especially since the OPs file has white space.

Hello ulises.rodriguez!

We believe that this post does not fit the main topic of this site.

Please tell us how this is related to bioinformatics.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

1 answer

With a one-line bash script:

awk -v RS= '{print > ("output-" NR ".txt")}' file_name

Log in to answer this question.