Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ AWK principles and commands and file input     - ARM assembler instruction debugging method (Programming)

- SHELL script to use anti SSH brute force and vsftpd (Linux)

- Linux and Unix systems really do network more secure (Linux)

- Installation and deployment of Hadoop 2.7.1 on Ubuntu 14.04 LTS (Server)

- RHEL 7.1 compile and install Ganglia 3.7.1 (Server)

- 10 tips daily Docker (Server)

- Linux (Debian) install software, missing dynamic link libraries .so (Linux)

- Ubuntu install Scala 2.10.x version (Linux)

- CentOS-based Kickstart automated installation practice (Linux)

- Help you to see Linux system architecture type 5 Common Commands (Linux)

- MySQL concat function is SQL injection (Linux)

- SecureCRT 7.0 Log Ubuntu 12.04 server via SSH service under Vmware (Server)

- Linux script commands - terminal recorder (Linux)

- C # function (Programming)

- Spring Data study notes -Helloworld (Programming)

- Oracle Bug caused by the collection of AWR Snapshot fault (Database)

- Memcached distributed caching (Server)

- Docker + OpenvSwitch build experimental environment VxLAN (Server)

- Usage Linux device tree (Programming)

- floating IP in OpenStack neutron (Server)

 
         
  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:      
 
- Oracle 12C truncate table cascade (Database)
- Android webView URL redirects affect goBack () (Programming)
- The multiplexed signal driving IO (Programming)
- Linux using RAID how to use Mdadm Tool Management Software RAID (Linux)
- How Datadog monitor Nginx (Server)
- Volatile keyword in C language understanding (Programming)
- How to Check notebook CPU temperature in Ubuntu (Linux)
- Compile Android libwebcore.so error occurs when solving (Programming)
- Bash code injection attacks through a special environment variable (Linux)
- JavaScript file loader LABjs API Explanation (Programming)
- extundelete: the Linux-based open source data recovery tools (Linux)
- Linux RPM default installation path (Linux)
- ctop: monitor container performance Linux command line artifact (Linux)
- Through the source code to install MySQL 5.6.26 under CentOS6 (Database)
- How to add two-factor authentication for Linux systems SSH (Linux)
- Stucts2 values on the page and how the attribute values corresponding to the Action (Programming)
- CoreOS use register mirror to build private warehouse (Linux)
- Under Ubuntu on how to use iptables firewall (Linux)
- Vim copy and paste register (Linux)
- Linux installed PCRE (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.