SoFunction
Updated on 2025-03-09

How to use grep command to find characters with tab (backspace) in Linux

The main posts that need to be deleted in the log file are separated by tab (backspace) characters; assuming that the log file name is.

The saved format and saved data are as follows:

Delete date                                                                                                                             �

 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 the command cat |grep '11'|wc is used, all logs will be counted.

You can see that there are tab (backspace) characters on each line around 11, so you can find them accurately through the regular expression of "tab (backspace) 11tab (backspace)".

But if you use the command cat |grep '\t11\t'|wc or cat |grep '\t11\t'|wc, you can't find any of them.

In fact, there are two ways to correctly match the tab (backspace) characters in Linux.

1: Use grep  $'\t'

2: Use grep 'press CTRL+V keys, and then press TAB keys'          Your file

Going back to the above question, you can use the following command

cat |grep $'\t'11$'\t' |wc

or

cat |grep ‘CTRL+V,TAB11CTRL+V,TAB'|wc

The above content is all about this article, I hope it will be helpful to everyone.