In the Linux system using awk text processing tools, sometimes need to merge multiple lines, which requires the use of awknext statement, the following small series will introduce you to the use of awk in Linux to achieve multi-line merge method, the need Friends can come to understand.
awknext statements use: Progressive match in circulation, if they are next, will skip the current line, simply ignore the following statement. And the next line is matched.
The code is as follows:
The text.txt content is:
a
b
c
d< Br>
e
[chengmo@centos5 shell]$ awk ‘NR%2==1{next}{print NR,$0;}’ text.txt
2 b
4 d
When the record line number is divided by 2 or more 1, the current line is skipped. The following print NR, $0 will not be executed. The next line begins and the program begins to determine the NR%2 value. At this time, the record line number is: 2, and the following statement block will be executed: ‘print NR,$0’
awk next use case:
The code is as follows:
Requirements:
File: text.txt Format:
web01[192.168.2.100]
httpd ok
tomcat ok
sendmail Ok
web02[192.168.2.101]
httpd ok
postfix ok
web03[192.168.2.102]
mysqld ok< Br>
httpd ok
The output format needs to be changed by awk:
web01[192.168.2.100]: httpd ok
web01[192.168.2.100]: Tomcat ok
web01[192.168.2.100]: sendmail ok
web02[192.168.2.101]: httpd ok
web02[192.168.2.101]: postfix ok
web03[192.168.2.102]: mysqld ok
web03[192.168.2.102]: httpd ok
Analysis:
Analysis needs to include "<quo;web&rdquo Go Skip, then you need to merge the content with the following line into one line.
[chengmo@centos5 shell]$ awk ‘/^web/{T=$0;next;}{print T“:\\t”$0;}’ test.txt
Web01[192.168.2.100]: httpd ok
web01[192.168.2.100]: tomcat ok
web01[192.168.2.100]: sendmail ok
web02[192.168.2.101 ]: httpd ok
web02[192.168.2.101]: postfix ok
web03[192.168.2.102]: mysqld ok
web03[192.168.2.102]: httpd ok< Br>
The above is the introduction of Linux using awk for multi-line merging. It is very convenient to use the next statement in the text. In the loop matching, if you encounter next, it will automatically skip, thus achieving multi-line merging. .
Python is a computer programming language. The succinct and extensible nature of the Python language
exfat is a file system for U disk. Many systems support the use of exfat format, bu
Linux disk management is mainly implemented by commands. Today, Xiaobian will sort out the commands
In order to speed up Fedora startup speed, some will change Fedora startup default, will start into
Linux how to delete the replacement variable value
How to use the command to synchronize the clock under Linux
Linux system how to create a scheduled task with crontab
How CentOS 6 modifies disk quota limits
Linux prompts [root@localhost ~]# iptraf when executing commands?
How to mount iPhone under Arch Linux system
What should I do if Ubuntu prompts the list error when opening the software center?
How to embed all LaTex fonts in PDF files under Linux
Linux configuration SSH service method
How does Ubuntu recover the GNOME Panel that was accidentally deleted?
64-bit Win7 system to play DOS classic software and games
Control Windows 98 Autorun with System Configurator
Creating a USB Recovery Disk for Surface RT
Win7 Ultimate system IE11 can not be uninstalled and reinstalled how to do
Win8.1 navigation optimization Startup into the desktop and other settings skills
Twenty-eight secret weapons hidden in XP
How to voice on WeChat on the computer?
How to solve WinXP broadband connection prompt error 764 problem