ive executed this command to delete all occurrences of "#" from a huge amount of files (about 3000)in folder train,
perl -pi -e "s/#//g" /Users/Kian/Desktop/Acsegment/espslabs/train/*
but I got this error: /bin/bash: /usr/bin/perl: Argument list too long
Can anyone suggest a way to avoid this error?
That's what xargs
is all about.
ls /Users/Kian/Desktop/Acsegment/espslabs/train |
xargs perl -i -pe's/#//g'
find
can do it too, and it allows you to select which files to modify much more flexibly.
find /Users/Kian/Desktop/Acsegment/espslabs/train \
-type f -maxdepth 1 \
-exec perl -i -pe's/#//g' {} +
Of course, you could also generate the file list in Perl.
perl -i -pe'BEGIN { @ARGV = map glob, @ARGV } s/#//g' \
'/Users/Kian/Desktop/Acsegment/espslabs/train/*'
But you have to escape spaces in the path unless you use bsd_glob
.
perl -i -pe'
use File::Glob qw( bsd_glob );
BEGIN { @ARGV = map bsd_glob($_), @ARGV }
s/#//g
' '/Users/Kian/Desktop/Acsegment/espslabs/train/*'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With