Argument list too long w/ sed | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

Argument list too long w/ sed

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-05-2013
openthomas openthomas is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 5 September 2013, 6:00 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Apple Argument list too long w/ sed

Hi all,

I am using GNU sed (named gsed under macports) in OSX. I have a directory with a series of files named pool_01.jpg through pool_78802.jpg. I am trying to use this command to rename the files to their checksum + extension.

Code:
md5sum * | gsed -e 's/\([^ ]*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/e'

That's GNU md5sum through macports.

However I get

Code:
-bash: /opt/local/bin/md5sum: Argument list too long



How best to get around this ?

Last edited by Franklin52; 09-05-2013 at 04:37 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 09-05-2013
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 19 December 2014, 4:53 PM EST
Location: NM
Posts: 10,312
Thanks: 297
Thanked 822 Times in 764 Posts
78000 file names is a lot of text when taken together. ARG_MAX is the limit to the total size of the arguments in bytes given to a command, including all env variables (like PATH, etc.)

one way around the problem, if I get what you are doing with sed:

Code:
ls | while read fname 
do 
 md5sum $fname | gsed -e s/\([^ ]*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/e'
done [... more code]

Sponsored Links
    #3  
Old 09-05-2013
openthomas openthomas is offline
Registered User
 
Join Date: Sep 2013
Last Activity: 5 September 2013, 6:00 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
That worked except you missed a comma. Thanks !

Finished script


Code:
#!/bin/sh

ls | while read fname 
do 
 md5sum $fname | gsed -e 's/\([^ ]*\) \(.*\(\..*\)\)$/mv -v \2 \1\3/e'
done

    #4  
Old 09-05-2013
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 18 December 2014, 1:32 AM EST
Location: Simplicity
Posts: 2,089
Thanks: 140
Thanked 613 Times in 556 Posts
Shorter and faster:

Code:
ls | xargs md5sum | ...

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
mv : Argument list too long VSom007 Shell Programming and Scripting 9 05-13-2013 12:30 PM
Argument list too long!! Naga06 Shell Programming and Scripting 2 07-11-2012 10:03 AM
Argument list too long for Sed command depakjan UNIX for Dummies Questions & Answers 4 06-20-2011 11:32 AM
Argument too long list error 22karthikreddy Shell Programming and Scripting 1 09-27-2010 02:12 AM
Argument list too long - SSH empyrean UNIX for Dummies Questions & Answers 6 06-10-2009 01:24 PM



All times are GMT -4. The time now is 08:07 PM.