LinuxQuestions.org
Help answer threads with 0 replies.
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-23-2004, 12:53 AM   #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, 01:01 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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 01:02 AM.
 
Old 08-23-2004, 02: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 02:18 AM.
 
Old 08-23-2004, 03:04 AM   #4
pcardout
Member
 
Registered: Jun 2003
Location: Socorro, New Mexico
Distribution: Debian ("lenny", "squeeze"), Linux Mint, XUbuntu
Posts: 218

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, 03:44 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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, 03: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, 03:57 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 11:53 AM
grep question djgerbavore Linux - Newbie 7 07-07-2004 08:11 AM
grep question Hockeyfan Linux - General 1 05-15-2004 03:09 AM
grep question vasanthraghavan Programming 3 04-23-2004 01:32 AM
grep question keyops Programming 2 04-09-2004 10:17 PM


All times are GMT -5. The time now is 09:07 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration