0

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.

1
  • I think it would help to see the actual field in 'input_list.txt'. $4, the variable, may not actually correspond to the name of the file that is downloaded from wget. Commented Aug 13, 2013 at 14:48

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.