0

INPUT (tab delimited)

HTR12   AT1G01370       Chr1    143564  145684  +
SDG42   AT1G01920       Chr1    316128  319650  +
SDG5    AT1G02580       Chr1    544783  549202  +

OUTPUT (tab delimited)

Chr1    143564  145684  HTR12   AT1G01370       +
Chr1    316128  319650  SDG42   AT1G01920       +
Chr1    544783  549202  SDG5    AT1G02580       +

my solution is

awk -v OFS="\t" '{print $3,$4,$5,$2,$1,$6}' input > output

But seems not good.

1
  • 1
    Any chance of seeing what seems not good really is? BTW, I think you mean awk -v OFS="\t" '{print $3,$4,$5,$1,$2,$6}' input > output
    – Tigger
    Nov 6, 2016 at 8:46

3 Answers 3

2

try

awk -F'\t' -v OFS='\t' '{print $3,$4,$5,$1,$2,$6}' input > output

this will set FS (field separator) for both

  • -F'\t' IFS (input),
  • -v OFS='\t' OFS (output).

I also swap $1 and $2

I tabbed you sample files, output is

awk -F'\t' -v OFS='\t' '{print $3,$4,$5,$1,$2,$6}' se.txt
Chr1    143564  145684  HTR12   AT1G01370       +
Chr1    316128  319650  SDG42   AT1G01920       +

and (add od -c to check for tab)

awk -F'\t' -v OFS='\t' '{print $3,$4,$5,$1,$2,$6}' se.txt | od -c
0000000   C   h   r   1  \t   1   4   3   5   6   4  \t   1   4   5   6
0000020   8   4  \t   H   T   R   1   2  \t   A   T   1   G   0   1   3
0000040   7   0  \t   +  \n   C   h   r   1  \t   3   1   6   1   2   8
0000060  \t   3   1   9   6   5   0  \t   S   D   G   4   2  \t   A   T
0000100   1   G   0   1   9   2   0  \t   +      \n
0000113
0
0

i Use space as field separator and tab in between fields i got perfect orientation.

awk -F" " '{print $3"\t"$4"\t"$5"\t"$2"\t"$1"\t"$6}' input.txt > output.txt

output:

Chr1     143564  145684  AT1G01370   HTR12   +
Chr1     316128  319650  AT1G01920   SDG42   +
Chr1     544783  549202  AT1G02580   SDG5    +
4
  • 2
    It's unclear why you would choose to use space as the input field separator and why you output explicit tabs instead of setting OFS="\t". Also, note the ordering of the fields in the output compared to what's in the question.
    – Kusalananda
    Sep 29, 2021 at 17:05
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 29, 2021 at 17:28
  • remove , from print as it insert space after tab.
    – Archemar
    Sep 29, 2021 at 18:53
  • Said differently, the question explicitly says: "INPUT (tab delimited)". Perhaps you copy/pasted the input locally and it resulted in spaces instead of tabs? See also Archemar's answer for the output field ordering -- it's ... 1/2/6, not 2/1/6 (which was maybe the OP's problem all along??). But at which point, you've basically recreated Archemar's answer.
    – Jeff Schaller
    Sep 30, 2021 at 11:24
-1

One tab is equal to 8 spaces so try with below code

awk '{printf "%8s%8s%8s%8s%8s%8s\n",$3,$4,$5,$1,$2,$6}' filename

    Chr1  143564  145684   HTR12AT1G01370       +
    Chr1  316128  319650   SDG42AT1G01920       +
    Chr1  544783  549202    SDG5AT1G02580       +

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .