simple grep problem

This is a discussion on simple grep problem within the Windows Programming forums, part of the Platform Specific Boards category; In my WindowsXP/dos window, how do I grep for a tab? I try > grep "\t" file.txt which gives me ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    57

    simple grep problem

    In my WindowsXP/dos window, how do I grep for a tab?

    I try
    > grep "\t" file.txt
    which gives me every line with a "t" in it, not tab.

    Thank you

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    When you parse the string "\t", instead look for a tab character.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    57
    Quote Originally Posted by Dave_Sinkula
    When you parse the string "\t", instead look for a tab character.
    Do you mean to hit the tab key instead of typing \t?

    (When I hit the tab key, doskey brings up file names)

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    No I mean interpret the character string "\t" to mean the tab character when you do a search.
    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
       while ( *argv )
       {
          printf("*argv = \"%s\"\n", *argv++);
       }
       return 0;
    }
    
    /* my output
    H:\test>test "\t" file.txt
    *argv = "H:\test\test.exe"
    *argv = "\t"
    *argv = "file.txt"
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    57
    Dave,

    I have no idea what you are talking about. You wrote a C program, which I understand.

    I want to execute a grep from a dos prompt.

    I am grepping the output of a C program (ctags). I want to print out all lines with a tab.

    Are you with me this far?

    My grep command, at the dos prompt, should look something like this:
    >grep x file.txt

    I don't know what x is. I want to print out all lines in file.txt which have a tab.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    [edit]Sorry, I'm reading this wrong.
    Last edited by Dave_Sinkula; 12-25-2005 at 09:06 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    57
    Dave, thank you for trying, I appreciate it.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Why are you trying to look for a tab? You might try \s, which matches a whitespace character . . . .

    [edit]
    Or you can write your own program to do it.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 08:10 PM
  3. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 09:49 AM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21