Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ sed and awk in shell usage and some examples     - Apple Mac computer to install Windows 10 Concise Guide (Linux)

- Linux top command to get started (Linux)

- Experts teach you how to identify the actual functional differences between the firewall (Linux)

- To protect the temporary files for Linux security (Linux)

- Oracle 10g after the failure to start the upgrade (Oracle instance terminated. Disconnection forced) (Database)

- Command line tool Tmux (Linux)

- Linux delete duplicate files Artifact: dupeGuru (Linux)

- Ubuntu system grub repair method (Linux)

- Debian installation (Linux)

- Linux / proc directory Comments (Linux)

- JSON data normalization (normalize) (Programming)

- High-performance JavaScript loaded and executed (Programming)

- Web server security policy (Linux)

- Xshell key authentication mechanism using a remote login Linux (Linux)

- CentOS 5.5 kernel upgrade installation iftop (Linux)

- Analysis of memory mapping process in Linux x86-32 mode (Linux)

- OpenSUSE / Linux network configuration (Linux)

- Android Studio simple setup (Linux)

- Ubuntu 14.04 modify environment variables (Linux)

- Analysis of Java exception (Programming)

 
         
  sed and awk in shell usage and some examples
     
  Add Date : 2017-08-31      
         
         
         
  Introduction

Operation and maintenance should always do with these two tools sed and awk, but to put them to good use is no easy task, it takes a long time to accumulate, rough paper used in everyday talk about some examples.

text

1 How to get the string string in shell length

echo $ {# string}
2 Replace text file in one or more spaces

sed -i "s / \ + / || / g" test
NOTE: \ + means that one or more of the previous character

3 Delete the text in the file "[" and "]" two characters

sed -i -e "s / \ [// g" -e "s / \] // g" text

Each column of text 4 text separated by commas, and now you want to delete the sixth column, then the output of the other columns, each separated by a space

awk 'BEGIN {FS = ","; OFS = ""} {$ 6 = ""; print $ 0}'

CPU 5 percent output for each user occupied

top -bn 1 | awk '{if (NR> 7) print $ 0}' | awk '{sum [$ 2] + = $ 9} END {for (i in sum) printf "% .2f% s \ n", sum [i], i} '| sort -nr

6 Statistics nginx's access.log each url access number and the flow output of the previous 10


awk '{print $ 7 "\ t" $ 10}' access_2010-12-8.log | awk '{S [$ 1] + = $ 2; S1 [$ 1] + = 1} END {for (i in S) print S [ i], S1 [i], i} '| sort -rn | head -10
     
         
         
         
  More:      
 
- Create RAID 1 (mirroring) with two disks (Linux)
- Installation Mesos + Marathon + Zookeeper under CentOS 7 (Server)
- Binding unofficial Google Drive and Ubuntu 14.04 LTS (Linux)
- Ubuntu users install the video driver Nvidia Driver 334.21 (Linux)
- Linux foundation tutorial: how to modify the host name on CentOS or RHEL 7 (Linux)
- Install Ubuntu 14.04 and Windows 8 / 8.1 dual-boot in UEFI mode (Linux)
- Oracle table compression Technology Introduction (Database)
- MongoDB3.0.6 wiredtiger MMAPv1 (Database)
- Ora-00020: maximum number of processes (500) exceeded (Database)
- How to import JNI resulting .so libraries in Android Studio (Programming)
- Linux security concerns again (Linux)
- Hadoop 2.0 Detailed Configuration Tutorial (Server)
- Unable to start the network after restart clone a virtual machine (Linux)
- How to configure security services under Linux (Linux)
- MySQL 5.6 master-slave replication configuration (Database)
- To configure Samba to share files with Windows under CentOS (Linux)
- Snapshot DataGuard (Database)
- MongoDB replication instance (Database)
- Fedora 23 How to install LAMP server (Server)
- Linux cd command Detailed (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.