Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ AWK principles and commands and file input     - MariaDB 10 Multi-source replication (Database)

- Cooling solutions Ubuntu system (Linux)

- Glibc support encryption by modifying the DNS (Programming)

- Oracle database on the hit rate of query summary (Database)

- Revised OpenJDK Java Memory Model (Programming)

- 4 lvcreate example commonly used commands (Linux)

- Spark read more HBase tables a RDD (Server)

- Linux non-root user uses less than 1024 ports (Linux)

- Deb package installation method under ubuntu (Linux)

- CentOS 7 RHEL 7 to reset the root password (Linux)

- wget command Walkthrough (Linux)

- Save the database data files into Oracle Learning (Database)

- Ubuntu install driver manager Mint Driver Manager and Device Driver Manager (Linux)

- How to upgrade to Oracle 11g Oracle 12c (Database)

- Oracle archive log size than the size of the online journal of the much smaller (Database)

- Lenovo Ultrabooks Ubuntu system can not open the wireless hardware switch solutions (Linux)

- Install GAMIT / GLOBK 10.50 software under Ubuntu 14.04 (Linux)

- Install snort intrusion detection system on Debian (Linux)

- Linux under DB2SQL1024N A database connection does not exist. SQLS (Database)

- Depth understanding of C language (Programming)

 
         
  AWK principles and commands and file input
     
  Add Date : 2017-02-22      
         
       
         
  First, awk Profile
 1,
 awk is the first three letters of the last name, on behalf of the three authors of the language, there are many versions of awk, including: Legacy awk, the new version of awk (nawk), GNU awk (gawk) and the like.
 There awk command awk program, enclosed in quotes or written instructions in the file and the input file these parts.
 2,
 [Root @ rhel helinbash] # which awk
 / Bin / awk
 [Root @ rhel helinbash] # which gawk
 / Bin / gawk
 [Root @ rhel helinbash] # ls -l / bin / awk / bin / gawk
 lrwxrwxrwx 1 root root 4 Oct 10 2013 / bin / awk -> gawk
 -rwxr-xr-x 1 root root 320416 Jan 15 2007 / bin / gawk
 [Root @ rhel helinbash] #
NOTE: After the examples are based on gawk command

Second, awk works
 1,
 The following names follow the steps to resolve the file name, for example awk processing
 (1)
 vim names
 Tom Savage 100
 Molly Lee 200
 John Doe 300
 (2)
 [Root @ rhel helinbash] # cat names.txt | cut -d '' -f 2
 

Savage
        Lee
 

[Root @ rhel helinbash] # cat names.txt | cut -d '\ t' -f 2
 cut: the delimiter must be a single character
 Try `cut --help 'for more information.
 [Root @ rhel helinbash] #
(3)
 [Root @ rhel helinbash] # gawk '{print $ 1, $ 3}' names.txt
  
  
 Tom 100
 Molly 200
 John 300
  
 [Root @ rhel helinbash] #

[Root @ rhel helinbash] # gawk '{print $ 1 $ 3}' names.txt
 

Tom100
 Molly200
 John300
 
[Root @ rhel helinbash] #

2,
 Schematic
 FS: Field separator (separator)
 OFS: Output Field Separator

Third, from the input file
 1,
 format:
 gawk '/ match string /'
 gawk '{} processing operation'
 gawk '/ match string / processing operation {}' file name
 2,
 [Root @ rhel helinbash] # gawk '/ root /' / etc / passwd
 root: x: 0: 0: root: / root: / bin / bash
 operator: x: 11: 0: operator: / root: / sbin / nologin
 [Root @ rhel helinbash] # grep root / etc / passwd
 root: x: 0: 0: root: / root: / bin / bash
 operator: x: 11: 0: operator: / root: / sbin / nologin
 [Root @ rhel helinbash] #
3,
 [Root @ rhel helinbash] # gawk '/ ^ root /' / etc / passwd
 root: x: 0: 0: root: / root: / bin / bash
 [Root @ rhel helinbash] #
4,
 [Root @ rhel helinbash] # gawk '/ ^ root /'
 root
 root
 root
 root
 studnet
 t ^ H ^ [[3 ~ ^ H ^ H ^ H this is a demo string wih ^ H ^ H iclcude root key woard
 
root hello abc
 root hello abc
 
[Root @ rhel helinbash] #
Note: The red font is filtered output, this is the interactive Run gawk
 5,
 [Root @ rhel helinbash] # gawk -F: '{print $ 1 $ 3}' / etc / passwd
 root0
 bin1
 daemon2
 adm3
 lp4
 sync5
 shutdown6
 halt7
 mail8
 news9
 uucp10
 operator11
 games12
 gopher13
 ftp14
 nobody99
 nscd28
 vcsa69
 rpc32
 mailnull47
 smmsp51
 pcap77
 ntp38
 dbus81
 avahi70
 sshd74
 rpcuser29
 nfsnobody65534
 haldaemon68
 avahi-autoipd100
 xfs43
 gdm42
 sabayon86
 Oracle500
 named25
 [Root @ rhel helinbash] #
6,
 [Root @ rhel helinbash] # gawk -F: '/ root / {print $ 1 $ 3}' / etc / passwd
 root0
 operator11
 [Root @ rhel helinbash] #
7,
 Print formatted output function
 awk command operation processing section is on the "{}" (in parentheses) in; print function variables and characters mixed with output. As the echo command linux

Fourth, from the command input
 1,
 Awk can also handle the results received through the pipeline linux commands, shell typically uses awk do deep processing.
 (1)
 format:
 Command | gawk '/ match string /'
 Command | gawk '{} processing operation'
 Command | gawk '/ match string / processing operation {}'
 (2)
 [Root @ rhel helinbash] # date
 Mon May 26 10:10:01 CST 2014
 [Root @ rhel helinbash] # date | gawk '{print "Month:" $ 2 "\ nYear:", $ 6}'
Month: May
 Year: 2014
 [Root @ rhel helinbash] #
(3) Note that the above example, a direct connection behind Month $ 2, and the other is between $ 6 and the Year of the comma, the decision by the OFS.
     
         
       
         
  More:      
 
- OpenStack image production in the CentOS 6.2 (Linux)
- 256 with rich colors decorate your terminal (Linux)
- Swift acquaintance of values and references, the circular reference, Agent Precautions (Programming)
- Thinking in Java study notes - initialization and cleanup (Programming)
- How to install Linux Kernel 4.0 On CentOS 7 system (Linux)
- Linux, MySQL / MariaDB Galera Cluster Setup Process (Database)
- Practical top command (Linux)
- Objective-C basic program structure (Programming)
- Rails project prepared some tips small experience (Linux)
- Java Set and List in the relationship and difference (Programming)
- Ubuntu server 8.04 Firewall Guide (Linux)
- To build a private Docker registry (Server)
- rpm package specify the installation path (Linux)
- Configuring Haproxy log support (syslog logging support) (Server)
- How to avoid two Chrome icon appears in ELementary OS Freya (Linux)
- Log analysis is done with Grafana Elasticsearch (Server)
- Installation Sublime Text 3 (Build 3065) text editor in Ubuntu (Linux)
- MongoDB in bulk timestamp change the date format (Database)
- Linux Fundamentals of the memory management mechanism (Linux)
- Security enhancements in Ubuntu ssh service (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.