-
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
-
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.
-
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 ]
-
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 ]
-
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!
-
cross posting is bad!!!!!
-
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.
-
-
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
-
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.
-
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
-
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
-
Forum Rules
|
|