我有以下包存储库格式
Package: enigma2-plugin-extensions-airplayer
Version: 0.3.9
Section: extra
Architecture: all
Maintainer: hellmaster1024 and DonDavici <hellmaster1024 and DonDavici@code.google.com/p/airplayer/>
MD5Sum: b0c862e749846521ea11eeae77ddf905
Size: 166268
Filename: enigma2-plugin-extensions-airplayer_0.3.9_mips32el.ipk
Source: ftp://code.google.com/p/airplayer//hellmaster1024 and DonDavici/airplayer-0.3.9.tar.gz
Description: Enigma2 Plugin AirPlayer by hellmaster1024 and DonDavici
OE: airplayer-0.3.9
HomePage: code.google.com/p/airplayer/
Priority: optional
Package: enigma2-plugin-extensions-atmolightd
Version: 0.7-pre22
Section: extra
Architecture: all
Maintainer: mamba0815 <mamba0815@gmx.li>
MD5Sum: af17593ec8ad4a00c1fa843ccb17be6f
Size: 851522
Filename: enigma2-plugin-extensions-atmolightd_0.7-pre22_all.ipk
Source: www.noip.com
Description: Sedulight/Atmolight/amBXlight/Karatelight for Enigma2
OE: 1.6
HomePage: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=136415
Priority: optional
现在我需要一个bash脚本,它在Loop中找到“Package Name”示例“enigma2-plugin-extensions-atmolightd”和“Filename”示例enigma2-plugin-extensions-atmolightd_0.7-pre22_all.ipk
我开始使用以下脚本
for i in `cat Packages.txt |grep Filename|cut -b 11-`; do
wget "http://sources.dreamboxupdate.com/opendreambox/1.5/dm7025/feed/$i";
done
我可以下载所有软件包 - 但我错过了软件包名称。 想要使用包名创建一个文件夹,然后将所有版本的包存储到此文件夹中。
可以肯定这可以通过Regex解决吗? 但我不擅长这个,......
迎接埃里希
#!/bin/bash
#
echo "Downloading all Packages from the feed"
rootPath="/tmp/Openwrt/Trunk"
#echo $rootPath
mkdir -p $rootPath
wget -O "$rootPath/Packages" http://enigma2.world-of-satellite.com/feeds/3.0/et9x00/3rdparty/Packages
while read -r p f; do
mkdir -p "$rootPath/$p" 2>/dev/null
wget -nc -P "$rootPath/$p" "http://enigma2.world-of-satellite.com/feeds/3.0/et9x00/3rdparty/$f"
done < <(awk -F ' *: *' '$1=="Package"{p=$2;next} $1=="Filename"{print p, $2}' "$rootPath/Packages")
答案 0 :(得分:0)
您可以使用awk:
while read -r p f; do
mkdir -p "$p" 2>/dev/null
wget "http://sources.dreamboxupdate.com/opendreambox/1.5/dm7025/feed/$f"
done < <(awk -F ' *: *' '$1=="Package"{p=$2;next} $1=="Filename"{print p, $2}' Packages.txt)
<强>解释强>
awk命令将输入字段分隔符用作:
,并在输入文件中搜索Package
和Filename
行。如果发现两个值都打印在带有空格分隔符的同一行中。
while read
命令读取变量p and f
中的两个值。这些变量用于进一步处理。
答案 1 :(得分:0)
另一个想法可能如下。
#!/bin/bash
#example_script.sh
package="";
filename="";
while read line
do
echo "$line" | grep "Package"
if [ $? -eq 0 ]; then
package=`echo "$line" | grep "Package" | cut -f 2 -d ":" | tr -d ' '`
mkdir -p "$package"
fi
echo "$line" | grep "Filename"
if [ $? -eq 0 ]; then
filename=`echo "$line" | grep "Filename" | cut -f 2 -d ":" | tr -d ' '`
cd "$package"
wget "YOUR_BASE_URL_GOES_HERE/$filename"
cd ..
fi
done < $1
然后打电话给它。
./example_script.sh filename.txt
* Read a file line by line assigning the value to a variable
* http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html
* How to trim whitespace from a Bash variable?
* http://unixhelp.ed.ac.uk/CGI/man-cgi?mkdir
* http://linux.die.net/man/1/tr