LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about Grep (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-grep-221151/)

irfanhab 08-22-2004 11:53 PM

Question about Grep
 
Hi all,


Is grep a tool that can only be used in conjunction with a pipe.
I mean
ls | grep "Xx"
does produce results
however
grep "Xx"
doesn't display anything instead, a new bash prompt doesnt appear, after giving this input.

Can one use it standalone.

Another questions:
I go
ls
I see files like
The\ Microsoft\ Computer\ Dictionary,\ Fifth\ Edition.chm*

how can I make the output appear like
The Microsoft Computer Dictionary, Fifth Edition.chm

Tinkster 08-23-2004 12:01 AM

Re: Question about Grep
 
Quote:

Originally posted by irfanhab
Is grep a tool that can only be used in conjunction with a pipe.
I mean
ls | grep "Xx"
does produce results
however
grep "Xx"
doesn't display anything instead, a new bash prompt doesnt appear, after giving this input.

Can one use it standalone.
grep bash /etc/passwd

In Unix/Linux everything is a file - STDIN is just a
special case. You can either pipe it, or use it by
its name :)


Quote:

Another questions:
I go
ls
I see files like
The\ Microsoft\ Computer\ Dictionary,\ Fifth\ Edition.chm*

how can I make the output appear like
The Microsoft Computer Dictionary, Fifth Edition.chm
Hmmm .. my ls doesn't display \ or * ... what are
your ls-options in env?


Cheers,
Tink

irfanhab 08-23-2004 01:15 AM

Well

grep "expression" directoy
like
grep "C++" /docs/programming
does not work
only
grep expression filename works

and the ls thingy
It only happens when I access a vfat (FAT32) filesystem, it doesnt happen in native linux filesystems, but still it is annoying.

anyways my LS options are
LS_OPTIONS= --color=auto -F -b -T 0

pcardout 08-23-2004 02:04 AM

Grep operates standalone
 
I love grep.

For years, hackers have kept phonebooks in text files (your friends names, addresses, birthdays etc.)

grep -i irfanhab phonebook

Would give me all the information I had about you in my phonebook.
-i is ignore case (useful!). THere are other options to specify the
length of "context" so that grep would print all the lines in phonebook that had your name as well as a couple above or below (that's the context).

You asked about

grep "Xx"

You got a valid answer to your question, but not sure if it was clear, so I repeat, differently, in case it helps.

grep "Xx" did not return to command line because it was searching
for the string "Xx" in the file stdin (your terminal). It was waiting for you to close the file with a Ctrl-Z.

So you'd want grep "Xx" filename to search for "Xx" in a particular file.

If you want to seach for "Xx" in every file in a directory, then
it's just

grep "Xx" *

... That works fine.

Can't help you on your ls question.

Tinkster 08-23-2004 02:44 AM

Quote:

Originally posted by irfanhab

grep "expression" directoy
like
grep "C++" /docs/programming
does not work
only
grep expression filename works
Try
grep "C++" /docs/programming/*

Quote:

and the ls thingy
It only happens when I access a vfat (FAT32) filesystem, it doesnt happen in native linux filesystems, but still it is annoying.

anyways my LS options are
LS_OPTIONS= --color=auto -F -b -T 0
Unset the -F and try again.

Cheers,
Tink

irfanhab 08-23-2004 02:19 PM

Thanks everyone,

just one little question how do you change environment variables?

Tinkster 08-23-2004 02:57 PM

By setting them to a new value...

e.g. export LS_OPTIONS=" --color=auto -b -T 0"

If you like what that does you'll have to
a) either look at your local bash-invocation
scripts (~/.bashrc, ~/.bash_login or ~/.bash_profile)
and change that there,
or
b)
in /etc/profile


Cheers,
Tink


All times are GMT -5. The time now is 10:16 AM.