0913&0915 Exercises: Shell Scripts, Sed&awk

Source: Internet
Author: User
Tags greatest common divisor

Knowledge Point Grooming: Click the link to enter


1. Shell Introduction and variables, scripting related concepts

2. Bash Programming: Condition testing

3. Bash Programming: arithmetic operations

4. Bash Programming: If statements
5. Bash Programming: Case statements, read and user interaction

6. Bash Programming: Process Control

7. Bash Programming: functions and Arrays

8. sed command--stream editor

9. awk Command--report generation tool             



Exercise 1:

Write a script: If a path does not exist, it is created as a directory, otherwise it is present, and the content type is displayed;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/98/wKiom1YBnRDBppXYAABURaCac7E650.jpg "/>


Run the script test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/95/wKioL1YBnRCAc9blAAC0OAKMlKU725.jpg "/>




Exercise 2:

Write a script to complete the following functions; Determine the given two values, whichever is greater; the method of the given number: script parameter, command interaction

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/98/wKiom1YBnRDihwUIAAD5UorLfOs973.jpg "/>


Run the script test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/95/wKioL1YBnRHSrhjFAAH2uqGwCXw770.jpg "/>



Exercise 3:

The sum of all odd numbers within 100 (at least 3 methods).

Method 1:

Echo ' seq-s ' + "1 2 ' = ' seq-s" + "1 2 100 | BC '

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/98/wKiom1YBnRDR1DVcAACP2VorLs8631.jpg "/>


Method 2: Implement with A For loop

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/95/wKioL1YBnRHAE7ZjAAA_0t0E3uo832.jpg "/>


Run the script test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/98/wKiom1YBnRGiNdCFAAA9tJETviY889.jpg "/>


Method 3: Implement with a while loop

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/95/wKioL1YBnRGhL6ZAAABbA6TmM0k776.jpg "/>


Run the script test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/98/wKiom1YBnRHxo-ZuAAA2h3mACwc766.jpg "/>


Exercise 4:

Write a script to implement the following functions:

(1) Pass two text file path to script;

(2) Show the number of blank lines in two files and their blank lines;

(3) Show the total number of files in two files and their total number of rows;

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/73/95/wKioL1YBnRHSiaStAAGLfT_VfkQ251.jpg "/>


Run the script test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/98/wKiom1YBnRGiv43lAAGgZ-kn_IQ195.jpg "/>



Exercise 5:

Write a script

(1) Prompt user to enter a string

(2) Judgment:

If quit is entered, exit the script

Otherwise, the string content of its input is displayed

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/73/95/wKioL1YBnRLybCdDAABdakILhWU378.jpg "/>


Run the script test:



Exercise 6:

Write a script to print the 2^n table; n equals a user-entered value

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/98/wKiom1YBnRjD-BsCAACwhRmjfLw700.jpg "/>


Run the script test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/73/95/wKioL1YBnRiBjL5uAAC14_dNfIk927.jpg "/>



Exercise 7:

Write a script that writes a few functions:

Function 1, to achieve the sum of the given two values;

Function 2, take a given two values of greatest common divisor;

Function 3, take a given two values of least common multiple;

The selection of the function and the size of the two numeric values are provided through interactive input.


(not yet understood, IQ recharge ...) )



0913&0915 Exercises: Shell Scripts, Sed&awk

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.