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 03: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: 20 October 2014, 6:07 PM EDT
Location: NM
Posts: 10,240
Thanks: 281
Thanked 802 Times in 746 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: 20 October 2014, 5:12 PM EDT
Location: Simplicity
Posts: 1,967
Thanks: 127
Thanked 573 Times in 520 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 11:30 AM
Argument list too long!! Naga06 Shell Programming and Scripting 2 07-11-2012 09:03 AM
Argument list too long for Sed command depakjan UNIX for Dummies Questions & Answers 4 06-20-2011 10:32 AM
Argument too long list error 22karthikreddy Shell Programming and Scripting 1 09-27-2010 01:12 AM
Argument list too long - SSH empyrean UNIX for Dummies Questions & Answers 6 06-10-2009 12:24 PM



All times are GMT -4. The time now is 04:44 AM.