简体   繁体   English

awk在新行上打印新列

[英]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. 我使用awk进行简单的计算,然后将结果打印在新的制表符分隔的列上。 It works, but awk prints the result on a column on a new line. 它可以工作,但是awk将结果打印在新行的列上。 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. 当我运行您的命令时,它对我来说很好用,假设您可以通过执行cat -v Input_file检查Input_file中是否包含回车符,那么可以使用以下命令首先将其删除。

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

Then you could give a shot to your own command. 然后,您可以尝试一下自己的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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