Run the grep command in linux to find the characters with a tab.

Source: Internet
Author: User

 

The main post to be deleted must be counted in the log file, and the log file is separated by tab characters. Assume that the log file name is delete. log.

 

Save the format and save the data as follows,

 

Delete date post type (11 as the main post, 12 as the reply) Post id operator id

 

12 71163578 1153089

11 71163800 134379

12 71163801 134379

11 71151662 2064561

2011-11-01 00:42 11 71163897 719476

11 71164159 2215597

12 71164712 2317663

12 71164820 111

12 71164841 622530

12 71164881 1999836

11 71163794 32254

12 71162281 32254

71165688 2296120

71165682 2296120

12 71165870 11568

11 71142268 1020

12 71167000 634940

11 70948995 604153

71167508 2100858

12 71168173 952148

 

 

 

From the log file, if you use the command cat delete. log | grep '11' | wc, all logs are collected.

 

You can see that each row has a tab (unspace) character on the left and right of 11, so you can use the regular expression "tab (unspace) 11tab (unspace)" for exact search.

 

However, if you use the command cat delete. log | grep '\ t11 \ T' | wc or cat delete. log | grep '\ t11 \ T' | one wc cannot be found.

 

 

 

In fact, there are two ways to correctly match the tab character in linux:

 

1: Use grep $ '\ t' for your file

 

2: press CTRL + V with grep, and then press TAB to press your file

 

 

 

Return to the problem above, you can use the following command

 

Cat delete. log | grep $ '\ t' 11 $' \ T' | wc

 

Or

 

Cat delete. log | grep 'ctrl + V, TAB11CTRL + V, tab' | wc

From the column in question 042

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.