bash: /bin/ls: Argument list too long

You should be able to replace ls ERR*_1_*.fastq with find . -name "ERR*_1_*.fastq".
This way, you can avoid having the wildcard expand into a huge argument list.

(The find output will include a leading "./", e.g. ./ERR001268_1_100.fastq . If that's undesirable, you can get rid of it with another sed command later in the pipeline.)


If the files already all exist within your directory, python's "glob" module might have a higher limit than bash's command line.

From the command line:

python -c "import glob; print glob.glob('ERR_*_1_*.fastq')"

To do the whole thing in python, the you could try something like this:

import glob
files = glob.glob("ERR_*_1_*.fastq")
trimmedfiles = [x.replace(".fastq","") for x in files]
trimmedfiles.sort()
for f in trimmedfiles:
    print f

This solution will sort the files alphabetically, and not numerically. For that you might want to add some key=lambda magic to the sort() method:

trimmedfiles.sort(key=lambda f: int(f.split("_")[2]))

Tags:

List

Ls

Fastq