如何对不同行的数据进行相减

发布于 2024-08-30 16:52:05 字数 105 浏览 3 评论 0原文

我有一个包含单列数字的文件。我必须从 row2、row3-row2 中的值减去 row1 中的值; row4-row3 、 row5-row4 等对于所有 rows 。有人可以帮我解决这个问题吗?

I have a file that has a single column of numbers. I have to subtract value in row1 from value in row2, row3-row2; row4-row3 , row5-row4 and so on for all the rows . Could anybody help me out with this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花之痕靓丽 2024-09-06 16:52:05

这是一个简单的 BASH 脚本

FILENAME=$1

while read line
do
  if [ -n "$prevLine" ]
  then
    curLine=$line
    echo $(($curLine - $prevLine))
  fi
  prevLine=$line
done < $FILENAME

,因此您可以将其输入到名为 rowdiff.sh 的文件或类似的文件中。然后你chmod u+x rowdiff.sh使其可执行,然后./rowdiff.sh file_with_numbers.txt

Here's a simple BASH script

FILENAME=$1

while read line
do
  if [ -n "$prevLine" ]
  then
    curLine=$line
    echo $(($curLine - $prevLine))
  fi
  prevLine=$line
done < $FILENAME

So you would type that into a file called rowdiff.sh or something like that. Then you chmod u+x rowdiff.sh to make it executable, then ./rowdiff.sh file_with_numbers.txt

痴者 2024-09-06 16:52:05

将文件加载到 OpenOffice Calc(或 Excel,如果需要)中,并假设您的数据从 A1 开始,在单元格 B2 中输入 =(B1-A1),然后复制并粘贴所有一直到数据集的底部。

Load the file up into OpenOffice Calc (or Excel, if you must), and assuming your data starts in A1, into cell B2 put =(B1-A1) and then copy&paste that all of the way down to the bottom of your dataset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文