How to use the grep command to find character _ Regular Expressions with Tab (BACKSPACE) under Linux

Source: Internet
Author: User

The main post that needs to be deleted in the log file statistics, and the log file is a tab (BACKSPACE) character separated; Suppose the log file name is Delete.log.

Save the format and save the data as follows,

Delete Date Post Type (11 main posts, 12 for replies) Post ID operator ID

2011-11-01 00:05 12 71163578 1153089
2011-11-01 00:19 11 71163800 134379
2011-11-01 00:19 12 71163801 134379
2011-11-01 00:20 11 71151662 2064561
2011-11-01 00:42 11 71163897 719476
2011-11-01 01:05 11 71164159 2215597
2011-11-01 03:44 12 71164712 2317663
2011-11-01 04:40 12 71164820 111
2011-11-01 04:46 12 71164841 622530
2011-11-01 05:03 12 71164881 1999836
2011-11-01 06:23 11 71163794 32254
2011-11-01 06:27 12 71162281 32254
2011-11-01 07:12 11 71165688 2296120
2011-11-01 07:12 11 71165682 2296120
2011-11-01 07:38 12 71165870 11568
2011-11-01 07:49 11 71142268 1020
2011-11-01 08:20 12 71167000 634940
2011-11-01 08:38 11 70948995 604153
2011-11-01 08:40 12 71167508 2100858
2011-11-01 08:59 12 71168173 952148

From the log file, if you use the command cat Delete.log |grep ' One ' |WC, all the logs will be counted.

You can see that 11 of each row has a tab (BACKSPACE) character, so you can find it precisely by using the Regular Expression tab (BACKSPACE) 11tab.

However, if you use the command cat delete.log |grep ' \t11\t ' |WC or cat delete.log |grep ' \\t11\\t ' |WC do not find one.

In fact, there are two ways to correctly match the tab (BACKSPACE) character in Linux

1: With grep $ ' t ' your file

2: With grep ' Press CTRL + V, and then press TAB ' your file

To go back to the question 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

The above content is the whole content of this article, hope to be helpful to everybody.

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.