LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 12-17-2007, 05:20 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Rep: Reputation: 30
problem with grep


Hi Everyone,

I have an issue, which i think is strange . I am working on a remote server , connected using OpenSSH client on WindowsXP. Everything works fine.
whenever i try to grep a text from files , which are in thousands inside a directory,the SSHclient reconnects itself from the server. I am not sure why this happens?
am using the following command to find a file, which consists of the text"xxxxxxx".

after cd to the directory , i issue:
grep XXXXXXX *


Please advise me.
Thank you
 
Old 12-17-2007, 06:25 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
I don't know what you mean by "reconnects with the server". You said that there are thousands of files in the directory. If that is the case, you could easily be running out of memory in the shell, because the argument "*" will expand to all of the files in the directory.

You could replace it with something like:
find ./ -maxdepth 1 -type f -exec grep 'XXXXXX' '{}' \;

or

find ./ -maxdepth 1 -type f -print0 | xargs -0 --max-args=200 grep 'XXXXXX'
 
Old 12-17-2007, 06:34 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Original Poster
Rep: Reputation: 30
Yes Guru,

Am not sure.There may be nearby to million files in numbers. The "ls " itself is consuming a lot of time.

"reconnects with the server"

I mean once i press return after the grep command, the sshclient is disconnected from the server, without any error or warning.


Is it ok for me to try with "find ./ -maxdepth 1 -type f -print0 | xargs -0 --max-args=200 grep 'XXXXXX'" after "cd" to the directory , where the files are located.
 
Old 12-17-2007, 10:25 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
You might want to use "grep -H" if you want the filename to be printed as well as the match. If you are only interested in the first few matches, you could pipe the output through the "tail" command.

Your last attempt probably crashed the shell or exceeded your quota.
 
Old 12-18-2007, 04:45 AM   #5
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 579

Original Poster
Rep: Reputation: 30
Thank you,

It worked with " find ./ -maxdepth 1 -type f -print0 | xargs -0 --max-args=200 grep 'XXXXXX'"
 
  


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
A grep problem baks Programming 16 05-28-2007 06:44 PM
grep problem spx2 Linux - Newbie 9 12-15-2005 02:22 AM
grep problem michaelsanford Linux - Software 2 05-20-2005 08:23 PM
Grep problem chup Linux - General 7 04-17-2004 01:08 AM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 01:47 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