wget bash函数没有杂乱的输出

时间:2015-05-01 14:16:17

标签: bash awk sed wget

我正在学习在wget函数中自定义bash并遇到问题。我想显示Downloading (file):%而不是wget的混乱输出。下面的功能似乎很接近我无法根据我的特定需求调用它。

例如,我的标准wget是:

cd 'C:\Users\cmccabe\Desktop\wget'
wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv

并将.csv作为.txt下载到指定目录中的所有凌乱的wget输出。

这个功能似乎会或多或少地做我需要的功能,但我似乎无法使用我的数据正常运行。以下是我的尝试。谢谢你:)。

#!/bin/bash
download() {
    local url=$1 wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv
    local destin=$2 'C:\Users\cmccabe\Desktop\wget'
    echo -n "    "
    if [ "$destin" ]; then
        wget --progress=dot "$url"  -O  "$destin" 2>&1 | grep --line-buffered "%" | \
        sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    else 
        wget --progress=dot "$url" 2>&1 | grep --line-buffered "%" | \
        sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
    fi
    echo -ne "\b\b\b\b"
    echo " DONE"
}

已编辑的代码

#!/bin/bash

download () {
url=http://xxx.xx.xxx.xxx/data/getCSV.csv
destin='C:\Users\cmccabe\Desktop\wget'
echo -n "    "
if [ "$destin" ]; then
wget -O getCSV.txt --progress=dot "$url"  -O  "$destin" 2>&1 | grep --line-buffered "%" | \
    sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
else 
wget -O getCSV.txt --progress=dot $url 2>&1 | grep --line-buffered "%" | \
sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'
fi
echo -ne "\b\b\b\b"
echo " DONE"
menu
}

menu() {
while true
do
    printf "\n Welcome to NGS menu (v1), please make a selection from the MENU \n
    ==================================\n\n
    \t 1  Patient QC\n
    ==================================\n\n"

    printf "\t Your choice: "; read menu_choice

    case "$menu_choice" in
    1) patient ;;
    *) printf "\n Invalid choice."; sleep 2 ;;
    esac
done
}

0 个答案:

没有答案