How to split all columns into multiple columns?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split all columns into multiple columns?
# 8  
Old 12-22-2014
Hi Ravinder, you're welcome. That approach will still leave a TAB at the end, plus it will introduce an extra space from the default OFS ( using OFS= would fix that but it would still introduce an extra TAB at the end).

The perl suggestion in post #5 will also work with more than 2 characters per field...
# 9  
Old 12-22-2014
Hello Scrutinizer/All,

I have tried and hope this time it wouldn't show tab at last. Last tab is coming because when last character comes it will put a tab as per our logic,
so then tab will be our last character then we can remove this. Here is the code.
Code:
awk '{gsub(/[[:space:]]/,X,$0);gsub(/./,"&\t",$0);gsub(/.$/,X,$0);print}' Input_file

Output will be as follows.
Code:
q       q       q       0       e       e       e       0       T       T       T       0       1       2       2       0       m       1       2
a       a       a       0       g       g       g       0       G       G       G       0       3       4       3       0       2       u       u
z       z       z       0       d       d       d       0       h       h       h       0       5       6       6       0       4       h       h
w       w       w       0       c       c       c       0       J       J       J       0       7       8       8       0       5       y       y
s       s       s       0       f       f       f       0       k       k       k       0       9       0       0       0       j       8       9
x       x       x       0       p       p       p       0       m       m       m       0       1       3       3       0       p       0       1

After checking with od it shows no /t after last character as follows.

Code:
0000000   q  \t   q  \t   q  \t   0  \t   e  \t   e  \t   e  \t   0  \t
0000020   T  \t   T  \t   T  \t   0  \t   1  \t   2  \t   2  \t   0  \t
0000040   m  \t   1  \t   2  \n   a  \t   a  \t   a  \t   0  \t   g  \t
0000060   g  \t   g  \t   0  \t   G  \t   G  \t   G  \t   0  \t   3  \t
0000100   4  \t   3  \t   0  \t   2  \t   u  \t   u  \n   z  \t   z  \t
0000120   z  \t   0  \t   d  \t   d  \t   d  \t   0  \t   h  \t   h  \t
0000140   h  \t   0  \t   5  \t   6  \t   6  \t   0  \t   4  \t   h  \t
0000160   h  \n   w  \t   w  \t   w  \t   0  \t   c  \t   c  \t   c  \t
0000200   0  \t   J  \t   J  \t   J  \t   0  \t   7  \t   8  \t   8  \t
0000220   0  \t   5  \t   y  \t   y  \n   s  \t   s  \t   s  \t   0  \t
0000240   f  \t   f  \t   f  \t   0  \t   k  \t   k  \t   k  \t   0  \t
0000260   9  \t   0  \t   0  \t   0  \t   j  \t   8  \t   9  \n   x  \t
0000300   x  \t   x  \t   0  \t   p  \t   p  \t   p  \t   0  \t   m  \t
0000320   m  \t   m  \t   0  \t   1  \t   3  \t   3  \t   0  \t   p  \t
0000340   0  \t   1  \n

Thanks,
R. Singh

Last edited by RavinderSingh13; 12-22-2014 at 11:36 AM.. Reason: Added a comment
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Split into multiple files by using Unique columns in a UNIX file

I have requirement to split below file (sample.csv) into multiple files by using the unique columns (first 3 are unique columns) sample.csv 123|22|56789|ABCDEF|12AB34|2019-07-10|2019-07-10|443.3400|1|1 123|12|5679|BCDEFG|34CD56|2019-07-10|2019-07-10|896.7200|1|2... (3 Replies)
Discussion started by: RVSP
3 Replies

2. Shell Programming and Scripting

Split multi columns line to 2 columns

I have data like this 1 a,b,c 2 a,c 3 b,d 4 e,f would like convert like this 1 a 1 b 1 c 2 a 2 c 3 b 3 d 4 e 4 f Please help me out (4 Replies)
Discussion started by: jhonnyrip
4 Replies

3. Shell Programming and Scripting

Split 5 columns into 3 columns

I have a big data set as follows 8.519 8.601 8.833 9.183 9.602 1.003 1.041 1.070 1.085 1.084 1.06 1.034 9.879 9.307 8.66 I simply want this to arrange like this 8.519 8.601 8.833 9.183 9.602 1.003 1.041 1.070 1.085 1.084 1.06 1.034 9.879 9.307 8.66 ... (2 Replies)
Discussion started by: cnn
2 Replies

4. Shell Programming and Scripting

Split text separated by ; in a column into multiple columns

Hi, I need help to split a long text in a column which is separated by ; and i need to print them out in multiple columns. My input file is tab-delimited and has 11 columns as below:- aRg02004 21452 asdfwf 21452 21452 4.6e-29 5e-29 -1 3 50 ffg|GGD|9009 14101.10 High class -node. ; ffg|GGD|969... (3 Replies)
Discussion started by: redse171
3 Replies

5. UNIX for Dummies Questions & Answers

Split a column into multiple columns at certain character count

Hey everyone, I have an issue with a client that is passing me a list of values in one column, and occasionally the combination of all the values results in more than an 255 character string. My DB has a 255 character limit, so I am looking to take the column (comma delimited file), and if it... (1 Reply)
Discussion started by: perekl
1 Replies

6. Shell Programming and Scripting

awk script to split file into multiple files based on many columns

So I have a space delimited file that I'd like to split into multiple files based on multiple column values. This is what my data looks like 1bc9A02 1 10 1000 FTDLNLVQALRQFLWSFRLPGEAQKIDRMMEAFAQRYCQCNNGVFQSTDTCYVLSFAIIMLNTSLHNPNVKDKPTVERFIAMNRGINDGGDLPEELLRNLYESIKNEPFKIPELEHHHHHH 1ku1A02 1 10... (9 Replies)
Discussion started by: viored
9 Replies

7. Shell Programming and Scripting

Split columns

Greetings, I have an input file with two columns. The first column has different codes. Each time I have a new code I need to split the columns into new ones. The input file looks like this CR124 1320 CR124 1138 CR124 682 CR124 629 CR124 592 CR124 580 CR124 537 CR161 3967 CR161 3656... (6 Replies)
Discussion started by: vanesa1230
6 Replies

8. UNIX for Dummies Questions & Answers

Split columns

Greetings, I have an input file with two columns. The first column has different codes. Each time I have a new code I need to split the columns into new ones. The input file looks like this CR124 1320 CR124 1138 CR124 682 CR124 629 CR124 592 CR124 580 CR124 537 CR161 3967... (2 Replies)
Discussion started by: vanesa1230
2 Replies

9. Shell Programming and Scripting

split one column into multiple columns

hey, i have the following data: 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 (7 Replies)
Discussion started by: zaneded
7 Replies

10. UNIX for Dummies Questions & Answers

split one column into multiple columns

hey guys... Im looking to do the following: 1 2 3 4 5 6 7 8 9 Change to: 1 4 7 2 5 8 3 6 9 Did use | perl -lpe'$\=$.%3?$":"\n"' , but it doesnt give me the matrix i want. (3 Replies)
Discussion started by: zaneded
3 Replies
Login or Register to Ask a Question