Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Shell脚本Linux中重命名文件_Linux_Bash_Shell_Mv - Fatal编程技术网

在Shell脚本Linux中重命名文件

在Shell脚本Linux中重命名文件,linux,bash,shell,mv,Linux,Bash,Shell,Mv,我想重命名从以下脚本下载的文件: 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 我想将$4(已下载的文件)重命名为一个较短的文件名,该文件名只包含相应的$1和$3术语。例如,wgencodebroadhistorinea549h

我想重命名从以下脚本下载的文件:

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
我想将$4(已下载的文件)重命名为一个较短的文件名,该文件名只包含相应的$1和$3术语。例如,
wgencodebroadhistorinea549h2azdex100nmalrep1.bam
变成
A549_H2azDex100nm.bam


我一直在玩
,但我不断收到mv命令的错误消息,并且
$4
是一个不好的变量名。如果您有任何建议,我们将不胜感激。

如果您使用wget的-O选项,则无需重命名文件:

#!/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
!/bin/bash
[-n“$BASH|u版本”]|{
echo“您需要Bash来运行此脚本。”
出口1
}
如果IFS=$'\t'读取-a输入,则执行以下操作
wget-O“${INPUT[0]}{INPUT[2]}.bam”ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/${INPUT[1]}/${INPUT[3]}”
完成

确保以UNIX文件格式保存文件,如
script.sh
,然后运行
bash script.sh

如果使用wget的-O选项,则无需重命名文件:

#!/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
!/bin/bash
[-n“$BASH|u版本”]|{
echo“您需要Bash来运行此脚本。”
出口1
}
如果IFS=$'\t'读取-a输入,则执行以下操作
wget-O“${INPUT[0]}{INPUT[2]}.bam”ftp://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/${INPUT[1]}/${INPUT[3]}”
完成

确保以UNIX文件格式保存文件,如
script.sh
并运行
bash script.sh

我认为在“input\u list.txt”中查看实际字段会有所帮助。变量$4可能实际上与从wget下载的文件名不符。我认为在“input\u list.txt”中查看实际字段会有所帮助“.$4,变量,实际上可能与从wget下载的文件名不对应。