Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...