Shell finishing (36) = = = Read the rules and write the series

Source: Internet
Author: User

(a) write the series as shown below

[Email protected] ding1]# bash 5.sh

2/1

3/2

5/3

8/5

13/8

21/13

34/21

55/34

89/55

144/89

233/144


The shell code is as follows:


#!/bin/bash


>aa

>bb

Echo 1 2 | Xargs-n1 >AA


For i in ' seq 20 '

Do

A= ' Cat AA | Sed-n ' $i ' P '

b= ' Cat AA |tail-1 '

echo $ (($a + $b)) >>aa

c= ' Cat AA | Sed-n ' $ (($i + 1)) ' P '

echo $c/$a >>BB

Done

Cat BB


The calculation results are as follows, using awk to calculate

[[email protected] ding1]# bash 5.sh |awk-f '/' {A+=$1/$2;print A} '

2

3.5

5.16667

6.76667

8.39167

10.0071

11.6261

13.2437

14.8619

16.4799

18.098

19.716

21.334

22.9521

24.5701

26.1881

27.8062

29.4242

31.0422

32.6603

[Email protected] ding1]#


This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1970438

Shell finishing (36) = = = Read the rules and write the series

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.