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.

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

That's GNU md5sum through macports.

However I get

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

:mad:

How best to get around this ?

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:

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

That worked except you missed a comma. Thanks !

Finished script

#!/bin/sh

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

Shorter and faster:

ls | xargs md5sum | ...