简体   繁体   中英

awk prints new column on a new line

please suggest me how to fix this annoying issue. I use awk to make a simple calculation and then print the result on a new tab separated column. It works, but awk prints the result on a column on a new line. Please have a look

     chr1   839976  840333  44  66151894
     chr1   855835  856060  23  66151894
     chr1   860112  860337  25  66151894

awk 'BEGIN { OFS = "\t" } { $6 = $3-$2 } 1 ' file1.txt > result1.txt

This command print something like this

   chr1 713869 714267 79 66151894
   398
   chr1 839976 840333 44 66151894
   357
   chr1 855835 856060 23 66151894
   225

Can you fix the command properly?

When I run your command it works fine for me, as a assumption could you please check if you have carriage characters in your Input_file by doing cat -v Input_file then you could use following commands to remove them first.

tr -d '\r' < Input_file > temp_file && mv temp_file Input_file

Then you could give a shot to your own command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM