We use Gitlab in the company intranet to build a Git server, in the actual use, need to get some warehouse data, but I do not understand the web, so I intend to directly on the server to do the warehouse processing, extraction information, and now
I. Issues and needs:
For example, there is a aa.list file that reads:
1 2 3 4A B c D
For script reads a file, I want to read in one row, read one row at a time, like the first time is 1 2 3 4, the second is a B c DBut I wrote this.
For I in "$
Workaround:
1. Use split command to cut large files, save 1 million lines per small file
Split parameter:
-B: The following can be divided into the file size, can add units, such as B, K, m, etc.;-L: Split by number of rows;
#按每个文件1000行来分割除
The shell itself cannot be multi-threaded, but it can simulate multithreading by starting the subprocess and putting the child processes into the background, in order to increase the efficiency of the script while not significantly increasing the
This script has been tested on the Ubuntu and CentOS versions, and the source code is much more straightforward:
The code is as follows
Copy Code
#!/bin/bash Line= ' =========== ' #linux发行版名称if [[-f/usr/bin/lsb_release]];
The script for this lesson is also shared in the share.
Day Fourth: Circular structure
Content outline:
application Example Analysis
For loop
While loop
The principle of the For loop
Achieve effect
Modified according to yesterday's menu.
Today's example is used to validate the legality of the parameters entered by the user, and the program is not complicated, as follows:
#!/bin/sh
# validalphanum-ensures that input consists only of alphabetical
# and numeric
This shell is to determine if the number entered is a reasonable float
The implementation code is as follows:
#!/bin/sh # Validfloat-Tests Whether a number is a valid floating-point value.
# This script cannot accept scientific (1.304E5)
Shuf-n5 Main.txt
Sort-r Main.txt | Head-5
awk-vn=5-vc= "' wc-l file '" ' Begin{srand () while (n
While read Line;do echo "$line $RANDOM";d One
Options for the Shuf command:
-E,--echo: treat each parameter as an input line-I,--input-range=lo-hi:
Script 1 Stop Lampp#!/bin/bash#set-XV Open debug mode?Count= ' Ps-ef|grep lampp|grep-v "grep" |wc-l ' # "" is the TAB key that holds down shift to appear ~ symbol, excluding the command count lines of grep itselfIf [$count-GT 0] # greater than one
1. Shell Script Parameters
The $n represents the nth parameter passed to the script, for example, $ $ = 1th argument, and $ = 2nd parameter ....
$# number of command-line arguments
The name of the current script
$* returns the
$? Represents the return value for executing the previous command: If 0 means execution succeeds, non 0 means execution fails$, $ 、。。。 Represents the parameter 1, parameter 2, respectively 、。。。$# indicates the number of parameters for this program$*/
Because the shell appears to be a common feature between UNIX systems and is standardized by POSIX. As a result, shell scripts can be applied to many systems once they are "written attentively". Therefore, the reason to use shell scripts is based on:
JMeter parametric section refer to previous articleShell parameter Description: Number of threads, $: Total concurrency Rampup time, $ $: script run time, $4: Each script cycle duration $: So the cycle duration#!/bin/bashReport_time= ' Date '
A few commandsThe script is based on the preceding log format. If your log format is different, you need to adjust the parameters following the awk.Analyze the UserAgent in the log The code is as follows:Copy code Cat access_20130704.log | awk-F
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