Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the grep command to find characters with tab under Linux

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use the grep command to find characters with tab under Linux. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

The main posts deleted need to be counted in the log file, and the log file is separated by tab (backspace) characters; suppose the log file is called delete.log.

The saved format and saved data are as follows

Delete date post type (11 is main post, 12 is reply) 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 '11' | wc, all logs will be counted.

You can see that there is a tab character around 11 of each line, so you can find it accurately through the regular expression of "tab" 11tab.

However, if you use the command cat delete.log | grep'\ T11\ t' | wc or cat delete.log | grep'\ T11\\ t' | wc can't find any of them.

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

1: use grep $'\ t' your files

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

To return to the above question, you can use the following command

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

Or

Cat delete.log | grep 'CTRL+V,TAB11CTRL+V,TAB' | wc

The above is all the contents of the article "how to use the grep command to find characters with tab under Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report