Two ways:
- grep quote control-v tab quote
- cat -T then pipe to grep '\^I'
First I created a file with tabs for testing. I typed "Hi there" then the tab character, then return, then "this is a " then control-V, then the tab character then "real tab", and then the next line without tabs:
$ cat > foo
Hi there
this is a ^ real tab
isn't it.
$ cat foo
Hi there
this is a real tab
isn't it.
- You can grep for the tab character directly (sort of) by typing quote, then control-v, then another quote:
$ grep " " foo
Hi there
this is a real tab
- cat -T is an option to show the tabs in a file as "^I".
It's tricky to grep for the "^I" though. grep \^I and grep "^I" don't work. You need grep '\^I'
$ cat -T foo
Hi there^I
this is a ^Ireal tab
isn't it.
$ cat -T foo | grep "^I"
$ cat -T foo | grep '\^I'
Hi there^I
this is a ^Ireal tab
All the companies I've every worked have always made tabs illegal in code (including GOOG).
ReplyDeleteIn emacs and vi you can expand all tabs to spaces...then you use a python (or whatever) mode for your editor that has the virtual tabs set where you want (but they are implemented with spaces, always)