This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
126} How do I grep for a line with a tab?
Dr John Stockton wrote:
>Timo Salmi <ts(ät)uwasa.fi> posted :
>>J Smith wrote:
>>>How do I grep for a line with a tab?
>>>grep "\t" file.txt
>>>does not work
>>Depends on the grep you use.
*)
> MiniTrue will do it, expressing the tab either as an actual tab or (in
> the default -x+ state) as \x09.
> At
mtr206b.zip
True, if you pardon the feeble pun. Likewise, the more common
G(nu)awk tool could be used. Within a
batch file one could have e.g.
gawk "/\t/{printf \"%%s\n\", $0}" MYFILE.TXT
or, in fact even
gawk "/\x09/{printf \"%%s\n\", $0}" MYFILE.TXT
Likewise,
sed could be used
sed -n "/\t/p" C:\_M\TEST.TXT
However, there may be complications dependind on the gawk and sed
versions. Not all of them recognize Windows long file names (LFNs).
Thus short file name (SFN) conversion might be first be needed. For
example
@echo off & setlocal enableextensions
set file_=C:\_D\TEST\My test file.txt
for /f "tokens=*" %%f in ("%file_%") do set file_=%%~sf
gawk "/\t/{printf \"%%s\n\", $0}" "%file_%"
endlocal & goto :EOF
Note that the SFN extraction is not immune against the poison
characters.
The extra programs can be avoided by using a pure command
line script FINDSTR solution:
@echo off & setlocal enableextensions
findstr /c:"TheLiteralTabCharacter" "C:\_D\TEST\My test file.txt"
endlocal & goto :EOF
How you enter the literal tab character depends on the text editor you
use.
*)