When doing the project today, we encountered a problem, that is, how to use the pipeline under the Linux command. We will certainly use the simple pipeline, just like this form
<span style="font-size:18px;">ls -a | grep *test</span>
Today’s problem is a bit complicated. It is to scan the system log in real time, from the last line after scanning to the end of the file, and match keywords. If they match, an alarm will be given. I use awk with grep command to achieve
Awk command is used to select log segment output as the input of grep command
awk 'NR>= beginLineNum&& NR<endLineNum logFileName | grep -nE pattern ;
But how to get the total row number of the current log becomes a problem. The command to get the total row number is
wc -l logFileName
But the result after WC is to be placed in the position of Ender linenum, which can not be realized by | method. After query, it is found that it can be realized by using the ‘` symbol (` symbol is the key under the ESC key on the keyboard)
So the way to do it is
awk 'NR>= beginLineNum&& NR<`wc -l logfileName` logFileName | grep -nE pattern ;
When executing commands in Linux, the commands in ‘will be executed first, and then other commands will be executed
“As standard input, the return value of the command inside is input into the command outside.
Read More:
- Mybatis passes in multiple parameters to mapper. And uses @param details to report an error
- How to solve the problem of “unable to open / dev / vmmon: broken pipeline” when running VMware virtual machine?
- Several methods of executing multiple commands in Linux shell
- Solution to the problem that listen TCP 0.0.0.0:3306: bind: address already in use port is occupied in Linux centos7
- Idea for Mac setting JVM running parameters to solve running stuck problem
- The solution of multiple markers at this line @ override
- Linux use ls to view the file color is all white solution, and Linux file color introduction
- Use subprocess to execute the command line, and the pipeline is blocked
- Solution to unbalanced load of multiple cards (GPU’s 0 card is too high) in Python model training (simple and effective)
- Graphics rendering pipeline diagram of OpenGL
- Solve the problem of multiple root tags in as
- Alpine Linux executable file crash report error / lib / x86 not found_ 64 Linux GNU / libc.so solution
- Solutions to the problem of “there are stopped jobs” in Linux
- How to solve the problem of Cannot find module’npmlog’ when installing nodejs under Linux
- Solve the problem of unable to start under zookeeper Linux
- Idea pop-up window out of memory, modify the parameters and start the no response solution
- How to solve the problem of error 15: file not found when Linux starts
- Android Studio error “Manifest merger failed with multiple errors, see logs” solution
- Linux novice: unable to locate package error solution
- Error in Maven POM file: multiple annotations found at this line solution