Skip to main content
added 1 character in body
Source Link
terdon
  • 252.8k
  • 69
  • 481
  • 720

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux, has -P for Perl Compatible Regular Expressions which lets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux has -P for Perl Compatible Regular Expressions which lets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux, has -P for Perl Compatible Regular Expressions which lets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file
deleted 96 characters in body
Source Link
terdon
  • 252.8k
  • 69
  • 481
  • 720

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux has -P for Perl Compatible Regular Expressions, but the most portable option is to use -E which enables Extended Regular Expressions. Either option etslets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux has -P for Perl Compatible Regular Expressions, but the most portable option is to use -E which enables Extended Regular Expressions. Either option ets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux has -P for Perl Compatible Regular Expressions which lets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file
Source Link
terdon
  • 252.8k
  • 69
  • 481
  • 720

As you already saw, \t isn't special for Basic regular Expressions, and grep uses BRE by default. GNU grep, the default on Linux has -P for Perl Compatible Regular Expressions, but the most portable option is to use -E which enables Extended Regular Expressions. Either option ets you use \t for tab characters.

However, what you want is much easier to do with awk. Just set the input field separator to a tab (-F '\t') and then print any lines whose number of fields (NF) is not 3:

awk -F'\t' 'NF!=3' file

That will print all lines in file with more or less than three fields. To limit to only more than three fields, use:

awk -F'\t' 'NF>3' file