1

Sometimes wget picks up extra parameters when downloading a file, example Aev264-yale_econ2521120.m4v?bri=40.1&brs=689.

Obviously all I want is Aev264-yale_econ2521120.m4v.

I've poked through the man pages and can't see anything that stands out that would fix this. Any ideas?

2 Answers 2

3

If you're downloading one file at a time, you can use the -O option, which acts kind of like a shell redirection for the downloaded data.

Otherwise, this bash snippet should take care of fixing up the filenames afterwards:

for f in *\?*; do
    mv "$f" "${f%%\?*}"
done
1

As a more general solution, the venerable rename script works nicely:

 $ rename 's/m4v.*$/m4v/' Aev264*.m4v*

I'm pretty sure it is already installed in /usr/bin on debian/ubuntu/mint distributions and is a 42 line script if it isn't installed (well actually it's perl, so it's only one line if you're not into the whole readability thing).

$ squish /usr/bin/rename
use strict; use Getopt::Long; Getopt::Long::Configure('bundling'); my ($verbose, $no_act, $force, $op); die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n" unless GetOptions( 'v|verbose' => \$verbose, 'n|no-act' => \$no_act, 'f|force' => \$force, ) and $op = shift; $verbose++ if $no_act; if (!@ARGV) { print "reading filenames from STDIN\n" if $verbose; @ARGV = <STDIN>; chop(@ARGV); } for (@ARGV) { my $was = $_; eval $op; die $@ if $@; next if $was eq $_; if (-e $_ and !$force) { warn "$was not renamed: $_ already exists\n"; } elsif ($no_act or rename $was, $_) { print "$was renamed as $_\n" if $verbose; } else { warn "Can't rename $was $_: $!\n"; } }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .