LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-09-2016, 12:08 PM   #1
bishop2001
Member
 
Registered: Apr 2015
Posts: 58

Rep: Reputation: Disabled
/bin/cat: Argument list too long


Greetings,
I have a command that looks like the following:
cat /someDir/alotOFFiles/* | grep something | sed something > saveResult.log

I am getting the message /bin/cat: Argument list too long.
How can I get this working? I see that xargs may work, but what would the command look like?
Thanks
 
Old 02-09-2016, 12:22 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
How about a simple for loop?

I would also suggest ditching grep as sed already has this ability.
 
Old 02-09-2016, 12:32 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by bishop2001 View Post
cat /someDir/alotOFFiles/* | grep something | sed something > saveResult.log
Man, that's ugly.

"Useless use of cat". It's a "thing"
See also http://www.linuxplanet.com/linuxplan...orials/6522/1/
 
Old 02-09-2016, 01:41 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Maybe sg like this (untested):
Code:
( find . -print0 | xargs -0 cat -- ) |\
grep something | sed something > saveResult.log
 
1 members found this post helpful.
Old 02-21-2016, 03:28 AM   #5
OregonJim
Member
 
Registered: Feb 2016
Posts: 98

Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Maybe sg like this (untested):
Code:
( find . -print0 | xargs -0 cat -- ) |\
grep something | sed something > saveResult.log
The cat would be unnecessary as grep can take the filename argument (and for that matter sed can take the place of both cat and grep)...

Last edited by OregonJim; 02-21-2016 at 03:33 AM.
 
1 members found this post helpful.
Old 02-21-2016, 07:26 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Yes but the following commands give different outputs:
Code:
cat /etc/passwd /etc/motd | grep 'a'
grep 'a' /etc/passwd /etc/motd
 
Old 02-21-2016, 08:56 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by NevemTeve View Post
Yes but the following commands give different outputs:
Code:
cat /etc/passwd /etc/motd | grep 'a'
grep 'a' /etc/passwd /etc/motd
Yes, you need to use "grep -h" when there are multiple input files and you do not want to see the file names in the output.[QUOTE=NevemTeve;5503722]Yes but the following commands give different outputs:
Code:
cat /etc/passwd /etc/motd | grep 'a'
grep -h 'a' /etc/passwd /etc/motd
 
  


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
-bash: /bin/: Argument list too long zeeshan673 Linux - General 4 02-22-2007 10:25 AM
Combines 16000 files into 1 single file > error tb: /bin/cat: Argument list too long guanyu Linux - General 4 02-09-2007 12:33 AM
bash: /bin/rm: Argument list too long? FiveFlat Linux - General 5 08-11-2004 11:29 PM
-bash: /bin/mv: Argument list too long balanagireddy Linux - General 2 07-27-2004 11:19 PM
/bin/rm: Argument list too long dragon49 Linux - Software 1 09-02-2003 12:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:23 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
Open Source Consulting | Domain Registration