Reputation: 251
I want to rename files I have downloaded from the following script:
exec < input_list.txt
while read line
do
get $line
wget ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/$2/$4
# Rename $4
mv $4 $1"_"$3".bam"
done
The input file (input_list.txt) is tab delimited and contains four columns. The first, $1= name, $2= wget address, $3= factor and $4 is the file name.
A549 wgEncodeBroadHistone H2azDex100nm wgEncodeBroadHistoneA549H2azDex100nmAlnRep1.bam
I want to rename $4 (the file that has been downloaded) to a shorter file name that only includes the corresponding $1 and $3 terms. For example, wgEncodeBroadHistoneA549H2azDex100nmAlnRep1.bam
becomes A549_H2azDex100nm.bam
I've played around with "
but I keep getting error messages for the mv command and that $4
is a bad variable name. Any suggestions would be greatly appreciated.
Upvotes: 0
Views: 1906
Reputation: 75498
You don't need to rename the file if you use wget's -O option:
#!/bin/bash
[ -n "$BASH_VERSION" ] || {
echo "You need Bash to run this script."
exit 1
}
while IFS=$'\t' read -a INPUT; do
wget -O "${INPUT[0]}_${INPUT[2]}.bam" "ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/${INPUT[1]}/${INPUT[3]}"
done < input_list.txt
Make sure you save the file in UNIX file format like script.sh
and run bash script.sh
.
Upvotes: 4