Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux administrator should command: sed and awk     - CentOS directory structure Explanation (Linux)

- Recent Consolidation Using Linux security module (Linux)

- Log4Net (Linux)

- Linux how to prohibit the use of Ping command (Linux)

- WinSCP to transfer text files will automatically convert the format (Linux)

- Linux CentOS configuration SVN + SVN hook (Server)

- Debian 7 and Debian 8 users how to install Oracle Java 8 (Linux)

- Oracle RAC node on the expulsion of the inspection process on OEL6.3 (Database)

- Linux server security settings to close unused ports (Linux)

- Process monitoring tools Supervisor start MongoDB (Database)

- Git build a team development environment operating drills (Linux)

- Radius server setup under CentOS (Server)

- Install minimize RHEL / CentOS 7 things to do (Linux)

- Let Git variety of colors and custom log format output (Linux)

- High-performance JavaScript loaded and executed (Programming)

- Oracle RMAN repair logical bad blocks (Database)

- UNIX how to restrict users by IP Telnet (Linux)

- Build ftp server under CentOS 6.5 (Server)

- 127.0.0.1 and localhost difference (Server)

- How to override the plain text files and directories soft connection in linux (Linux)

 
         
  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:      
 
- JSON data normalization (normalize) (Programming)
- How to Install terminator 0.98 on Ubuntu and Linux Mint (Linux)
- Linux security-related basics (Linux)
- Docker use Dockerfile created since the launch of the service support SSH container mirror (Server)
- Linux module mechanism of (Programming)
- STL source code analysis - iterator each container classification (Programming)
- MySQL 5.7.9 source compiler installation instructions (Database)
- To configure and use multiple Tomcat under Linux environment (Server)
- CentOS6.5 install SVN & visual management tools iF.SVNAdmin (Server)
- Django how to generate content in non-HTML formats (Programming)
- Redis-2.8.17 installation and configuration process some errors (Linux)
- Java programmers talk about those advanced knowledge and direction (Programming)
- Kubernetes Cluster Setup problems encountered and solutions (Server)
- CentOS Linux Optimization and real production environment (Linux)
- Necessity in Java packages (Programming)
- OpenSSL Introduction and compilation steps on Windows, Linux, Mac systems (Linux)
- TPCC-MySQL Benchmark (Database)
- Mac OS X 10.9 build Nginx + MySQL + php-fpm environment (Server)
- Ora-14450: attempt to access ah transactional temptable already in use (Database)
- CentOS6.5 setup Oracle 11gR2 startup (Database)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.