Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux administrator should command: sed and awk     - Virt Related Command Summary (Linux)

- Linux kernel RCU (Read Copy Update) lock Brief - prequel (Linux)

- Linux iptables: combat scenes (Linux)

- Wireless LAN security solutions (Linux)

- ntop monitoring software configuration and installation (Linux)

- Openfire achieve load balancing cluster by Nginx (Server)

- Actual SSH port forwarding (Linux)

- VSFTPD Security (Linux)

- Linux crontab use (Linux)

- Ubuntu install video conversion tool Selene (Linux)

- Django1.5 Custom User Model (Programming)

- Moosefs Distributed File System Configuration (Server)

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

- JavaScript event handling Detailed (Programming)

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

- Without Visual Studio .NET Windows application development (Programming)

- Linux shared libraries .so file name and Dynamic Link (Linux)

- Realize screen recording and playback via Linux command (Linux)

- Sturdy build secure Linux server (Linux)

- Oracle Data Guard LOG_ARCHIVE_DEST_n optional attribute parameters (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:      
 
- These days have been tossing in the Linux under the ASP.NET 5, on the next in the other operating systems in the ASP.NET 5 or. NET applications, in order to complete the MS VM (CoreCLR) run is not far Reach, the effect of the application.

Cur
(Server)
- CentOS 6.6 compile and install phpMyAdmin configuration PostgreSQL9.4.1 (Database)
- Linux SVN installation and configuration graphic tutorials (Server)
- Quick paging ROW_NUMBER conducted (Database)
- Local port forwarding using iptables under linux (Server)
- shell script: MySQL startup script simple (Database)
- Those things packaged using Gradle to Android (Programming)
- Python closure and function objects (Programming)
- CentOS card fails to start at boot progress bar certmonger solve (Linux)
- JIRA 3.6.2 Upgrade from older version to the new version 6.0.8 (Linux)
- Upgrading Oracle 11.2.0.1.0 to 11.2.0.3.0 (Database)
- Nginx server security configuration (Server)
- Ubuntu 14.10 / 14.04 / 12.04 virtual users to install the printing software Boomaga (Linux)
- Linux System shutdown procedures (Linux)
- Linux tar compressed exclude a folder (Linux)
- Linux Security (Linux)
- How to use SHA256 checksum files download (Linux)
- Redis is installed and set up Ubuntu 14.04 from the environment under the main ssdb (Server)
- Linux System Administrator Network Security Experience (Linux)
- AFNetworking + Nginx HTTPS communication server + (Server)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.