In linux, You Can batch modify the IP content in an IP file containing a large amount of data and deduplicate the content.

Source: Internet
Author: User

In linux, You Can batch modify the IP content in an IP file containing a large amount of data and deduplicate the content.

As an apprentice in linux, I shared my experiences in solving this small problem. I used a small skill to solve this problem and found that linux terminals are very powerful, the following describes the problem in detail and the solution.

Problem description: To analyze logon Ip addresses, there are many log files with different Ip addresses. First, you must combine all log files into one log file, change the last Ip address to 0. For example, if the original IP address is 127.0.0.1, the current Ip address is 127.0.0.0.

Solution: use linux terminal commands

1. Merge multiple log files into one log file:

Cat test1.log test2.log test3.log> test. log

2. test. log contains the Ip addresses of all files. How can I change the last Ip address to 0? The point is that at first I wanted to use a regular expression to modify the Ip address, but I did not get the result, so I used a small trick:

1> Create a New test_middle.log in the current directory to keep the backup.

2> cut-d.-f1, 2, 3 test. log> test_middle.log

3> cat test_middle.log found that the IP address is similar to 127.0.0. I think everyone knows the role of the last shall statement. That's right, it's word segmentation. Take the first three paragraphs and write them to test_middle.log.

4> Add ". 0 ", and then write it to test. log, shall Script: sed's/$ /&. 0/g 'test_middle.log> test. log

 

Note: There are more than one solution to the problem. If you have a good solution, you may wish to share it with others. While learning, please respect the fruits of others' work. So, reprinted please indicate the source: http://www.cnblogs.com/ForeverLover/p/5085509.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.