Thread: simple grep problem

  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,005
    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,005
    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,005
    [edit]Sorry, I'm reading this wrong.
    Last edited by Dave_Sinkula; 12-25-2005 at 10: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,057
    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, 09:10 PM
  3. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 10: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