A script used shell to extract data from the database to generate a. xml file. Only 1000 pieces of data are generated in each file. So the while read line is used as the loop. A problem was found during file counter creation. During execution, the
First, redirect method; Piping method: Cat $FILENAME | While Read lineFunction While_read_line () {Cat $FILENAME | While Read lineDoEcho $LINEDone}Note: I only call this method the pipe method, compared to everyone should be able to see it. When the
Description:
Although the problem is not big, it is really disgusting. My goal is to process access logs.
Logs are separated by \ t for easy processing. data needs to be filtered and processed.
I don't want to filter it into a temporary file and
Transfer from http://openwares.net/linux/while_read_line_last_line.htmlJust used, thank you very much, stay here for backup;While reading line reads a file, if the last line of the file does not have a newline character \ n, then read reads the last
There are many ways to read one file at a row in Linux, the most common of which is the method in the following script, and the most efficient and most used method. In order to give you an intuitive feeling, we will test the execution efficiency of
After more than two months of hard work, this series of blog posts is coming to an end.ArticleIt can help you in your future work and hope to have the opportunity to communicate with you technically and learn from each other, at the same time,
Yesterday before work, the boss gave a batch of log database IP address, need to count the Log table message field Top 10 results, and output to an Excel file.Spot checks, there are two types of table names that end in the date of the day. Due to
Shell scripting to manage multiple servers at the same time, without the use of ansible, automatic manual implementationSSH does not log on to the Machine execution command (if you have to implement password-free login)ssh 127.0.0.1 ‘ifconfig‘ssh 127
1. Event Description:
1 ,#! /Bin/bash
Cat ../ip.txt | while read line
Do
Echo $ line
SSH $ line "ls"
Done
The result is recycled once and then exited. The reason is that while uses the redirection mechanism. All the information in the file is read
1. For I in 'ls *. mp3'
Common Mistakes:
for i in `ls *.mp3`; do # Wrong!
Why is it wrong? Because the for... in statement is segmented by space, the file name containing space is split into multiple words. If you encounter 01-Don't eat the
Conditional Select if statement 选择执行: 注意:if语句可嵌套 单分支 if 判断条件;then 条件为真的分支代码 fi 双分支 if 判断条件; then 条件为真的分支代码 else条件为假的分支代码 fi 多分支 if 判断条件1; then 条件为真的分支代码 elif 判断条件2; then 条件为真的分支代码 elif 判断条件3; then
VII. non-direct reference variables:
Three methods of assigning values to standard (direct) variables are provided in shell:1. assign values directly.2. Store the output of a command.3. Store the results of a certain type of computing.However, all
12 methods for linux shell to process text line by line 1. cat $ filename | while read line example: function while_read_line {cat $ filename | while read line do www.2cto.com echo "$ line ": # This line does not do anything. The return value is 0
This article mainly introduces examples of shell programmingFirst, the logical judgment if statement 1. Judging the age?[[email protected] 9_1 ]#cat iftest.sh #!/bin/bashread -p "Please input your age:" age ## 判断用户输入的必须是数字if [[ "$age" =~ ^[0-9]
How to read a file:First step: Pass the contents of the file to the while by pipe (|) or redirect (The second step is to call read in the while and read the contents of the file one line at a time and pay the value to the variable following read.
The latest when looking at a shell data, according to the textbook, but the following error, can not runAs follows, the simple script:#!/bin/bashcat | while Read Line do Echo $line Done awk'{print $}')The following error occurred while
There are a lot of ways, and here are three ways to write:
Writing a:
Copy Code code as follows:
#!/bin/bash
While Read line
Todo
Echo $line
Done
Writing two:
Copy Code code as follows:
#!/bin/bash
Cat
Loops are often used in shell programming, and the commonly used loops are for and while loops. While loops read files by default in rows, and for loops read file-splitting files with spaces, this article combines some examples of current web usage
Three, Shell script Development Basic Specification
System functions in 1,/etc/init.d/functions action using the method:
Show XXXX, and the right side shows the green OK Word: action "xxxx"/bin/true
Display XXXX, and the right side shows the red
Shell function return value, generally in three ways: return, argv, Echo
1) Return StatementThe Return Value of the shell function, which can be the same as that of other languages, returned through the return statement.Example:
#!/bin/bash
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.