Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ AWK principles and commands and file input     - Struts2 interceptor simulation (Programming)

- System Security: Build Linux with LIDS steel castle (Linux)

- Use PuTTY key authentication mechanism for remote login Linux (Linux)

- Binary Packages Golang (Linux)

- Linux screen command (Linux)

- Java enum use (Programming)

- LMMS 1.03 install on Ubuntu 14.04 (Linux)

- Installation and use Docker under Ubuntu 14.04 (Linux)

- The difference between vi and nano (Linux)

- Ubuntu install Tonido private cloud services (Server)

- Automatic and Manual Proxy Settings Switch GNOME Shell Extension Proxy Switcher Recommend (Linux)

- Linux System Getting Started Learning: Repair (Linux)

- Ubuntu 12.04 64-bit installation Redmine + Git + ReviewBoard (Linux)

- Linux based exercises, interview questions (Linux)

- CentOS6.6 ordinary users to use sudo command to borrow root user privileges (Linux)

- Linux script to copy the folder to all folders with the same name (Linux)

- ORA-12537: TNS: connection closed error process (Database)

- Spark build standalone version cluster (Server)

- Disk partition MBR (Linux)

- Oracle table of nested loop connection (Database)

 
         
  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:      
 
- Linux, set and view environment variables (Linux)
- MultiWriter: while the ISO image concurrent writes 20 USB Startup Disk (Linux)
- Java deserialization test (Programming)
- Linux Network Security Tips Share (Linux)
- Linux firewall settings -DNS server articles (Server)
- Web server security policy (Linux)
- RHEL 6.4 installed MySQL 5.6.27 (Database)
- Thinking in Java study notes - Access modifiers (Programming)
- LVS + Keepalived the DR mode (Server)
- Detailed reference Oracle 11g Partition (Database)
- Oracle user lock how to know what causes (Database)
- Smooth upgrade to OpenSSH 6.7 Procedure (Linux)
- Valgrind * not * leak check tool (Linux)
- Linux how to handle file names that contain spaces and special characters (Linux)
- Live Wallpaper for Linux release adds dynamic background (Linux)
- DRBD rapid installation and deployment (Server)
- SecureCRT session buffer size settings (Linux)
- To batch create users under Linux (Linux)
- In Debian 4.3 compiler under Linux-2.6.28 kernel Summary (Programming)
- Linux FAQ - How to fix tar:Exitingwith failure status due to previous errors (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.