我有下面的包存储库格式
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脚本,它可以在循环中找到“包名”示例“enigma2-plugin-扩展名-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")发布于 2014-02-25 18:35:30
您可以使用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)解释:
:,并在输入文件中搜索Package和Filename行。如果找到这两个值,则用空格分隔符在同一行中打印。while read命令读取变量p and f中的两个值。这些变量用于进一步的处理。发布于 2014-02-26 02:25:58
另一个想法可能如下所示。
#!/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
https://stackoverflow.com/questions/22022966
复制相似问题