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 11-22-2002, 05:59 PM   #1
albean
Member
 
Registered: Sep 2002
Distribution: fc2
Posts: 113

Rep: Reputation: 15
searching through a file


Hi,

I know there is a way to spit out the contents of a file to the screen or pipe it into another command. In dos its the 'type' command. what is it in linux?

And the how would I pipe it into grep?

I want to search a file for the word YYY and only print out the lines with YYY in them to the screen.

Thanks
 
Old 11-22-2002, 06:06 PM   #2
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
In this case you have a lot of posibilites just like:
Quote:
I want to search a file for the word YYY and only print out the lines with YYY in them to the screen.
cat filename | grep YYYY for instance!

Last edited by markus1982; 11-23-2002 at 05:12 AM.
 
Old 11-22-2002, 07:11 PM   #3
albean
Member
 
Registered: Sep 2002
Distribution: fc2
Posts: 113

Original Poster
Rep: Reputation: 15
Does that cut command work on all distros? I have the cut command but running cut filename outputs this:

cut: you must specify a list of bytes, characters, or fields
Try `cut --help' for more information.


Now, i did a man on cut but it reqires 'a list of bytes, characters, or fields' but i think there has to be an easier way to do what i want to do.
I saw somebody do this a long time ago.
 
Old 11-22-2002, 07:19 PM   #4
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
man grep
 
Old 11-22-2002, 08:28 PM   #5
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 55
Marcus made a typo it is cat command not cut.
 
Old 11-23-2002, 10:39 AM   #6
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
There is no reason to
"cat | grep "

since grep handles the reading of a file by itself.
just

grep YYY filename
 
Old 11-23-2002, 12:15 PM   #7
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Quote:
There is no reason to
"cat | grep "

since grep handles the reading of a file by itself.
just

grep YYY filename
True! But he asked for how to pipe information also so I thought why not just combine those 2 in 1 answer ... thanks for pointing that out though
 
Old 11-23-2002, 08:40 PM   #8
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
True. It looks like you gave him what he asked for and I amended that
to be what (I thought) he wanted. Ah. . . customer service.
 
Old 11-23-2002, 09:16 PM   #9
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Yep, anyways prob solved so that's fine
 
  


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
searching a file in my hardisk... itz2000 Linux - Newbie 1 10-31-2005 01:45 PM
File Searching gfrair Linux - Newbie 1 03-14-2005 07:24 PM
[c] searching for a word in a file saiz66 Programming 1 10-04-2004 10:46 PM
File Searching JC404 Linux - Newbie 2 08-02-2003 09:45 PM
searching through a binary file mccareth Programming 3 04-08-2002 06:51 PM


All times are GMT -5. The time now is 05:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration