I have a white-spaces delimited text file. I want to put a tab (\t) between the first and second column (or after the first white-space) and untouch the rest of the white-spaces. Would you let me know the best way to do it.
LA
I have a white-spaces delimited text file. I want to put a tab (\t) between the first and second column (or after the first white-space) and untouch the rest of the white-spaces. Would you let me know the best way to do it.
LA
$perl -pe 's/ /\t/' test
test1 pts/2 Jun 28 11:10 0:21 14041
test2 pts/3 Jun 28 11:10 0:20 14055
test3 pts/4 Jun 28 11:11 0:20 14073
root pts/4 Jun 28 11:11 0:20 14073
$cat test
test1 pts/2 Jun 28 11:10 0:21 14041
test2 pts/3 Jun 28 11:10 0:20 14055
test3 pts/4 Jun 28 11:11 0:20 14073
root pts/4 Jun 28 11:11 0:20 14073
Thanks...I guess the above code is based on the first white space. In my case, between column 1 and 2 there are some rows with more than one space in between. Is it possible to accomodate it (if more than one spaces are there make it always tab -delimited between column 1 and 2.
LA
what is mean by "column 1 and 2 there are some rows with more than one space in between"
post the sample input file and output file
Below is my input file
cgd1_10
cgd1_100
cgd1_1000
cgd1_1010
cgd1_1020
cgd1_1030
cgd1_1040
cgd1_1050
cgd1_1060 GO:0003674 // GO:0005488
cgd1_1070 GO:0003674 // GO:0003676 // GO:0005488
cgd1_1080
cgd1_1090
cgd1_110
cgd1_1100 GO:0003674 // GO:0003824 // GO:0004177 // GO:0006508 // GO:0008150 // GO:0008152 // GO:0008233 // GO:0008238 // GO:0008239 // GO:0008451 // GO:0009987 // GO:0016787 // GO:0016806 // GO:0017088 // GO:0019538 // GO:0043170 // GO:0044237 // GO:0044238 // GO:0044260 // GO:0044267
cgd1_1110 GO:0006629 // GO:0006643 // GO:0006644 // GO:0006650 // GO:0006658 // GO:0006659 // GO:0008150 // GO:0008152 // GO:0008610 // GO:0008654 // GO:0009058 // GO:0009987 // GO:0044237 GO:0044238 // GO:0044255 // GO:0046467 // GO:0046474
I need a a tab only between column 1 and column 2. For example cgd1_1060 is column 1 and GO:0003674 is column 2. when i did the above comment, there were some spaces between column 1 and column 2 after the tab. I want to remove those spaces after the newly introduced tab.
LA
nawk '{printf("%s\t%s",$1,$2); for(i=3;i<=NF;i++){printf(" %s",$i); if(i==NF)printf("\n"); }}' inputfile
This what I got when I implemeted the recent awl command which is not the format I needed as out put
cgd1_10 cgd1_100 cgd1_1000 cgd1_1010 cgd1_1020 cgd1_1030 cgd1_1040 cgd1_1050 cgd1_1060 GO:0003674 // GO:0005488
cgd1_1070 GO:0003674 // GO:0003676 // GO:0005488
cgd1_1080 cgd1_1090 cgd1_110 cgd1_1100 GO:0003674 // GO:0003824 // GO:0004177 // GO:0006508 // GO:0008150 // GO:0008152 // GO:0008233 // GO:0008238 // GO:0008239 // GO:0008451 // GO:0009987 // GO:0016787 // GO:0016806 // GO:0017088 // GO:0019538 // GO:0043170 // GO:0044237 // GO:0044238 // GO:0044260 // GO:0044267
cgd1_1110 GO:0006629 // GO:0006643 // GO:0006644 // GO:0006650 // GO:0006658 // GO:0006659 // GO:0008150 // GO:0008152 // GO:0008610 // GO:0008654 // GO:0009058 // GO:0009987 // GO:0044237 GO:0044238 // GO:0044255 // GO:0046467 // GO:0046474
My output should be in separate lines even when a line only contain the first string
$nawk '{for(i=1;i<=NF;i++){if(i==1){printf("%s\t",$i);}else if(i==2){printf("%s ",$i);} else {printf(" %s",$i);} if(i==NF)printf("\n"); }}' inputfile
cgd1_10
cgd1_100
cgd1_1000
cgd1_1010
cgd1_1020
cgd1_1030
cgd1_1040
cgd1_1050
cgd1_1060 GO:0003674 // GO:0005488
cgd1_1070 GO:0003674 // GO:0003676 // GO:0005488
cgd1_1080
cgd1_1090
cgd1_110
cgd1_1100 GO:0003674 // GO:0003824 // GO:0004177 // GO:0006508 // GO:0008150 // GO:0008152 // GO:0008233 // GO:0008238 // GO:0008239 // GO:0008451 // GO:0009987 // GO:0016787 // GO:0016806 // GO:0017088 // GO:0019538 // GO:0043170 // GO:0044237 // GO:0044238 // GO:0044260 // GO:0044267
cgd1_1110 GO:0006629 // GO:0006643 // GO:0006644 // GO:0006650 // GO:0006658 // GO:0006659 // GO:0008150 // GO:0008152 // GO:0008610 // GO:0008654 // GO:0009058 // GO:0009987 // GO:0044237 GO:0044238 // GO:0044255 // GO:0046467 // GO:0046474
Thanks..it worked
perl -lne 's/\s+/\t/;print' inp