根据其前面的列修改文本列 [英] Modify text column based on the column before it

查看:58
本文介绍了根据其前面的列修改文本列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,其前28行只是单词.从第29行到第100行,我获得了A,B和C的原子的位置信息及其3d坐标.现在,我想对第29-100行以与Y(第三列)相关的方式更改Z(第四列):

Z = Z + sin(Y/10 * Pi).仅在航站楼有可能吗?谢谢.

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

解决方案

Perl解决方案:

perl -lane '$F[3] += sin($F[2]/10 * 4 * atan2 1, 1) if 29 .. 100;
            print "@F"
           ' input_file > output_file

  • -n逐行读取输入
  • -a将空格上的每一行拆分为@F数组
  • -lprint
  • 添加换行符
  • 4 * atan2 1, 1是π
  • 29 .. 100仅适用于给定范围内的行

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

解决方案

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

这篇关于根据其前面的列修改文本列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆