Simple piped commands...WTF???

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Simple piped commands...WTF???

Post by alex.barylski »

Code: Select all

ls -al | cat | grep "Something"
Basically I am trying to search through a list of file contents looking for a match...the above doesn't work...

Anyone care to enlighten me please :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The file contents?

Code: Select all

grep -Pi "something" *
Search all files, show lines where "something" exists (case-insensitive)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Simple piped commands...WTF???

Post by Weirdan »

Hockey wrote:

Code: Select all

ls -al | cat | grep "Something"
Anyone care to enlighten me please :)
Works for me. Btw, cat is unnecessary here.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I am trying to locate files with certain class names.

Code: Select all

la -alr | grep class MyClass_*
Doesn't work. I'm listing recursively in the base directory to ensure I list every file which indeed is what is happening, as is demonstrated without the | grep command.

but when I add the grep command (with or without cat) I am getting nothing displayed to screen, maybe I am expecting the wrong results?

How do I get a list of files which match the grep, basically those which have class MyClass_ inside the file?

Cheers :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

grep class MyClass_*
search all files having a name starting with MyClass_ for the word class. You have to mark class MyClass_* as beeing one parameter with quotes.

Code: Select all

egrep --recursive 'MyClass_' *
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Got it thanks :)
Post Reply