LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-22-2004, 11:53 PM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
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
 
Old 08-23-2004, 12:01 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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

Last edited by Tinkster; 08-23-2004 at 12:02 AM.
 
Old 08-23-2004, 01:15 AM   #3
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
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

Last edited by irfanhab; 08-23-2004 at 01:18 AM.
 
Old 08-23-2004, 02:04 AM   #4
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("jessie", "squeeze"), Linux Mint (Serena), XUbuntu
Posts: 221

Rep: Reputation: 24
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.
 
Old 08-23-2004, 02:44 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 08-23-2004, 02:19 PM   #6
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
Thanks everyone,

just one little question how do you change environment variables?
 
Old 08-23-2004, 02:57 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep question djgerbavore Linux - Newbie 3 11-04-2004 10:53 AM
grep question djgerbavore Linux - Newbie 7 07-07-2004 07:11 AM
grep question Hockeyfan Linux - General 1 05-15-2004 02:09 AM
grep question vasanthraghavan Programming 3 04-23-2004 12:32 AM
grep question keyops Programming 2 04-09-2004 09:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration