finding a "tab" with grep


Results 1 to 12 of 12

Thread: finding a "tab" with grep

  1. #1
    Join Date
    Apr 2002
    Posts
    120

    finding a "tab" with grep

    Hey folks, another linux/unix newbie here trying to get some basics down. I cant seem to find out how to search for a "tab" using the grep command. Here are some things ive tried so far:
    grep '<tab>' filename
    grep '(actually hitting tab here)' filename
    grep '/t' filename
    grep '\t' filename
    grep '[[:space:]]' filename
    etc etc.
    Does anyone know what the proper way to search for a tab is? The actual reason i need it is of course much more complicated than this example but just knowing how to find tab would be enough. Thanks a ton!

    --Morphman, Linux Newbie

  2. #2
    Join Date
    Mar 2001
    Posts
    729
    You may be able to just use the ASCII code for tab somehow. Just a thought. There probably is a cleaner way. Heh, I'm actually kinda surprised the '(actually hitting tab here)' didn't work.

  3. #3
    Join Date
    Jan 2001
    Location
    Yonkers, NY USA
    Posts
    525
    I don't know how to do it with grep but you can use perl to make a really simple grep like program that will allow tabs. \t is the perl regex for tab.
    Code:
    #!/usr/bin/perl -w
    #
    use strict;
    
    my($pattern, $filename) = @ARGV;
    
    open (FIND, $filename) ||
            die "Can't open filename: $!";
    
    while (<FIND> ) {
            $pattern =~ s/\"//g;
    
            if(/$pattern/) {
                    print $_;
            }
    }
    
    exit 0;
    just save and chmod it and use it like grep.

    ./program pattern filename

    [ 18 April 2002: Message edited by: debiandude ]
    Get my public gpg key

  4. #4
    Join Date
    Apr 2000
    Location
    Linköping, Sweden
    Posts
    140
    I posted a reply to your thread in General... If you have awk you can use

    awk '/\t/' file_name

    to "grep" for tab

    [ 18 April 2002: Message edited by: marvin ]

  5. #5
    Join Date
    Apr 2002
    Posts
    120
    I also replied back in the general forum. It does in fact work for awk but i need to make substitutions with sed actually so it complicates things. Is there a way to pipeline the output from awk into sed and change it that way? It would be easiest to see my other post
    As for that little perl program, im totally perl illiterate! Ive only used C++ and assembly and im trying to learn shell programming for linux and unix now. Maybe ill get to perl eventually though. hehe, thanks for the help though!

  6. #6
    Join Date
    Sep 2000
    Location
    The Big Dig
    Posts
    494
    cross posting is bad!!!!!

  7. #7
    Join Date
    Apr 2002
    Posts
    120
    well, you dont have to look at the other post. they are independent except for the guy who actually pointed out that i have another post.

  8. #8
    Join Date
    Sep 2000
    Location
    The Big Dig
    Posts
    494
    Originally posted by morphman:
    <STRONG>well, you dont have to look at the other post. they are independent except for the guy who actually pointed out that i have another post. </STRONG>
    since I go to both Programming and General Linux questions, I see both. And it annoys me. Next time, post only in the most relevent section, not every one you feel you should put it in.



    edit: normally the HAL's will lock or delete one of your threads if you cross-post. But they don't seem to be around right now....

    STRIKE!!!

    [ 19 April 2002: Message edited by: Danger Fan ]

  9. #9
    Join Date
    Apr 2002
    Posts
    120
    Sorry bud, but what would you do? Nothing was happening on this post really and i need/needed answers as fast as i could because its really halting my progress and i need to make some big scripts, and the sooner the better. I feel i was justified in posting on the general linux questions because i need an answer if i can get it. Sorry if it ticks you off and i apologize for wasting your time because you read them both but i really need help.

    -Morphman

  10. #10
    Join Date
    Mar 2001
    Posts
    729
    Next time, it would probably be better if you posted to two completely separate places. (e.g. here and a newsgroup) Cross-posting in a forum is always a bad thing.

  11. #11
    Join Date
    Apr 2002
    Posts
    120
    For anyone who was/is actually curious about the answer to my original question i found the answer. To insert a tab you hit ctrl + v then ctrl + i and that will insert a tab at the command prompt! Thanks for any help!

    --Morphman

  12. #12
    Join Date
    Mar 2013
    Posts
    1

    Thankyou after almost 10 years

    Morphman, want to thank you for posting the answer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •