Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux administrator should command: sed and awk     - Fedora 8 configured Heartbeat (Linux)

- What happens after the MySQL disk space is full (Database)

- Linux Study of --CentOS create local yum repository (Linux)

- Source code to compile and install MySQL 5.7.9 (Database)

- 10 Regulation of painless SQL Schema (Database)

- Linux find command detailing (Linux)

- How to install Eclipse Luna IDE on CentOS 7 / RHEL 7 (Linux)

- The user how to install Notepadqq 0.41.0 under ubuntu and debian (Linux)

- File compression and packaging commands under Linux (Linux)

- OpenGL ES 3.0 vertex buffer (Programming)

- Why use Docker (Programming)

- Acting on JavaScript events (Programming)

- To compiler and install MariaDB-10.0.20 under CentOS 6.6 (Database)

- MySQL performance comparison of large amounts of data storage (Database)

- Compile and install Redis and register as a system service under RedHat5.8 environment (Database)

- How to monitor Nginx (Database)

- Oracle Shared Server Configuration (Database)

- How to manage your to-do list with the Go For It on Ubuntu (Linux)

- Use MySQL optimization of security to prevent misuse of aliases (Database)

- Oracle GoldenGate Installation and Configuration Tutorial Introduction (Database)

 
         
  Linux administrator should command: sed and awk
     
  Add Date : 2018-11-21      
         
         
         
  We do not let the next generation of Linux and Unix administrators forget initialization scripts and basic tools Benefits

I had time to see a post on Reddit, "how to manipulate text files." This is a very simple needs, like the day we met as usual Unix people. His problem is, how to delete duplicate rows in the file, leaving only the non-repetition. It sounds simple, but when the file is large enough, there will be a bit more complicated.

This problem There are many different answers. You can use almost any language to write such a script, just put in the time and complexity of the code may vary. Depending on your personal level, it will probably take 20-60 minutes. But if you use Perl, Python, Ruby one, you may soon realize it.

Or you can use one of the following methods, make you very heart-warming: only awk.

The answer is by far the most simple, the easiest way to solve the problem. It is a single line!

awk '! seen [$ 0] ++'
Let's see what happens:

In this command, in fact, I hide a lot of code. awk is a text processing language, and it is with a lot of presets. The first thing you see is actually the result of a for loop. awk assumes that you want to loop process each line of the input file, so you do not need to explicitly specify it. awk is also assumed that the data need to print output processing after you, so you do not need to specify it. Finally, awk is assumed that the last sentence cycle instruction execution after the end of this one no longer requires you to specify it.

This example is seen in a string associated with the name of the array. $ 0 is a variable that represents the entire current line. Therefore, this command is translated into human language "for each line of the file to be checked, if you have not seen it, print it out." If a key does not exist in the associative array is added to the array, and to increase its value, so awk next encounter the same row will not match (the condition is "false"), which is not printed.

Some people think this is an elegant, others argue it may cause confusion. Any use awk are in the daily work of the first category. awk is designed to do this. In awk, you can write multiple lines of code. You can even use awk write some disturbing complex functions. But in the end it is, awk is a text-processing program carried out, usually by pipeline. Remove (not necessary) circular definition is common and efficient usage, but if you like, you can also use the following code to do the same thing:

awk '{if print $ 0 (seen [$ 0]!); seen [$ 0] ++}'
This will produce the same results.

awk is a perfect tool for the job done. However, I believe many administrators - especially the new administrator will instead use Bash or Python to accomplish this task, because of its knowledge and understanding of the ability of awk looks over time slowly being forgotten . I think this is a question mark, because of the lack of understanding of previous solutions, those who have solved the problem for decades suddenly appeared.

shell, grep, sed and awk is the foundation of Unix. If you can not be very easy to use them, you will be bound to live their own, because they constitute the command line and scripts to interact with the Unix system foundation. Learn how these tools work is one of the best ways to observe real-life examples and experiments, you can find a lot in various Unix-derived systems initialize the system, but Linux distributions they have been replaced by systemd.

Millions of Unix Shell Scripting and Unix administrators understand how the tools to read, write, modify, and used in the initialization script. Initialization scripts for different systems are very different, even different Linux distributions are also different. But they are derived from sh, and they are used like sed, awk also like grep core command-line tool.

Every day I hear a lot of people complain about the initialization script too "old" and very "difficult." But in fact, the initialization scripts and tools Unix administrators, like every day, but also provides a very good way to become more familiar with and habits of these tools. He said initialization scripts difficult to read and hard to use actually is to admit your lack of familiarity with Unix based tool.

Speaking on Reddit sees, I have encountered this problem from a new entrants to the Linux system administrator, "and asked whether he should have to go to school system initialization old sysvinit". Most of the answers to this post are positive - Yes, we should learn sysvinit systemd and two. One commentator even pointed out that the initialization script is a good way to learn the Bash. The other news is, Fortune 50 company strong has no plans to migrate to systemd-based release.

But that reminds me that this is indeed a problem. If we continue along the way to eliminate from the script and the operating system core components to develop, due to the neglect of the contact, we will inadvertently make the new administrator is difficult to learn the basic Unix tools.

I do not know why someone would want in layer after layer of abstraction to cover internal Unix, but this continues to make possible a new generation of system administrators become just press the button of the workers. I think this is not a good thing.
     
         
         
         
  More:      
 
- Linux system commands to view hardware information (Linux)
- Linux / BSD firewall M0n0wall Profile (Linux)
- Linux Security Raiders SSH tools SCP uses examples to explain in detail (Linux)
- DVD production using CentOS installation source within the company Yum (Linux)
- Ubuntu 14.10 / 14.04 / 12.04 virtual users to install the printing software Boomaga (Linux)
- IDS Intrusion Detection System built (Linux) (Linux)
- Node.JS different ways to install under Ubuntu 15.04 (Linux)
- Linux system find command Detailed (Linux)
- CentOS ClamAV antivirus package updates (Linux)
- Several Ceph performance optimization of new methods and ideas (2015 SH Ceph Day after flu reference) (Server)
- About Auto Layout and frame (Programming)
- Git Tutorial Comments (Linux)
- Linux file system (inode and block) (Linux)
- Ubuntu install ruby (Linux)
- MongoDB, Cassandra, HBase transaction design strategy (Database)
- Chromium Install Flash Official Guide (Linux)
- Oracle 11g em start newspaper site's security certificate has a solution to the problem (Database)
- CentOS 6.4 Python 2.6 upgrade to 2.7 (Linux)
- Ubuntu 15.10 15.04 14.10 14.04 Install Ubuntu Tweak (Linux)
- C ++ hash function (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.