Linux Shell counts the number and replacement of words

Source: Internet
Author: User

1. count the number of occurrences

: % S/178 // ng

Text Test

711[10.235.170.22:8123]  0             10.232.20.178     1648042        1648042         0             2013-07-29 20:01:35711[10.235.170.22:8123]  11            10.232.20.178     6445135        6129386         315749        2013-07-29 20:19:40711[10.235.170.22:8123]  129           10.232.20.178     2220052        2220052         0             2013-07-29 19:33:04711[10.235.170.22:8123]  111           10.232.20.178     4939938        4754688         185250        2013-07-29 20:19:40711[10.235.170.22:8123]  123           10.232.20.178     284227         284227          0             2013-07-29 19:33:00711[10.235.170.22:8123]  112           10.232.20.178     4393638        4262994         130644        2013-07-29 20:19:40711[10.235.170.22:8123]  121           10.232.20.178     413891         413891          0             2013-07-29 19:33:00711[10.235.170.22:8123]  130           10.232.20.178     2803552        2803552         0             2013-07-29 19:33:04711[10.235.170.22:8123]  10            10.232.20.178     6558889        6235520         323369        2013-07-29 20:19:40711[10.235.170.22:8123]  106           10.232.20.178     5080974        4886037         194937        2013-07-29 20:19:40:%s/178//ng

As a result, it appears in 10 rows and 10 times in total. N, indicating only the number of matched reports, without actual replacement.

10 matches on 10 lines  


2. Replace matching items
% S indicates replacement.

: % S/178/ggg

The result is

711[10.235.170.22:8123]  0             10.232.20.ggg     1648042        1648042         0             2013-07-29 20:01:35711[10.235.170.22:8123]  11            10.232.20.ggg     6445135        6129386         315749        2013-07-29 20:19:40711[10.235.170.22:8123]  129           10.232.20.ggg     2220052        2220052         0             2013-07-29 19:33:04711[10.235.170.22:8123]  111           10.232.20.ggg     4939938        4754688         185250        2013-07-29 20:19:40711[10.235.170.22:8123]  123           10.232.20.ggg     284227         284227          0             2013-07-29 19:33:00711[10.235.170.22:8123]  112           10.232.20.ggg     4393638        4262994         130644        2013-07-29 20:19:40711[10.235.170.22:8123]  121           10.232.20.ggg     413891         413891          0             2013-07-29 19:33:00711[10.235.170.22:8123]  130           10.232.20.ggg     2803552        2803552         0             2013-07-29 19:33:04711[10.235.170.22:8123]  10            10.232.20.ggg     6558889        6235520         323369        2013-07-29 20:19:40711[10.235.170.22:8123]  106           10.232.20.ggg     5080974        4886037         194937        2013-07-29 20:19:40
10 substitutions on 10 lines  


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.