Modify text column based on the column before it

╄→尐↘猪︶ㄣ 提交于 2019-12-25 07:43:34

问题


I have a file whose first 28 rows are just words. Starting from 29th to 100th row, I have position information of atoms for A, B and C, and their 3d coordinates. Now what I would like to do is to change Z (the 4th column) in a way related to Y (the 3rd column) for Row 29-100:

Z = Z + sin(Y/10*Pi). Is that possible just in the terminal? Thanks.

A 0.016333 0.003203 0.472723
A 0.016333 0.035228 0.472723
B 0.016333 0.067253 0.472723 
B 0.016333 0.099278 0.472723 
C 0.016333 0.131303 0.472723 
C 0.016333 0.163328 0.472723

回答1:


Perl solution:

perl -lane '$F[3] += sin($F[2]/10 * 4 * atan2 1, 1) if 29 .. 100;
            print "@F"
           ' input_file > output_file
  • -n reads the input line by line
  • -a splits each line on whitespace into the @F array
  • -l adds a newline to print
  • 4 * atan2 1, 1 is π
  • 29 .. 100 is true only for lines in the given range


来源:https://stackoverflow.com/questions/37514800/modify-text-column-based-on-the-column-before-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!