If a data file looks like:snp200 snp1 snp100 snp32 1 1 0 2 0 0 0 2 2 2 2 1...how can I break the line when snp.. finish and use them as column names and then divide the rest of digits equally (total number of digits in each row should be equal to numbers of column names in the  first row )and place them in subsequent rows as each. in this small example there are 4 column names and so the rest of rows have 4 should have 4 digitsoutput:snp200 snp1 snp100 snp321 1 0 20 0 0 22 2 2 1 ...any suggestion by considering that the real data is indeed huge(more than 32000 column names)
How to split a huge line of characters into several lines with equal numbers of columns?
text processing
One option is to use a perl regex, like this:cat in.txt | perl -pe 's/(([^ ]+ +){4})/$1\n/g' > out.txtThe regular expression said to find one or more not spaces followed by one or more spaces and group the previous 2 things in a set of 4 then add a new line after each match.Test case:echo snp200 snp1 snp100 snp32 1 13454356 0 2 0 0 0 2 2 2 2 1 | perl -pe 's/(([^ ]+ +){4})/$1\n/g'snp200 snp1 snp100 snp32 1 13454356 0 2 0 0 0 2 2 2 2 1