たとえば、sed、awk、またはPythonがあります。
元のtxtファイルには548行があります。
したがって:
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
これに関して:
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0002/sn0002.mp3
http://twit.cachefly.net/audio/sn/sn0003/sn0003.mp3
答え1
最後の2つのフィールド(例コードフラグメント)で使用されたプレフィックスがsn
最後のフィールドの3番目のフィールドから派生したと仮定すると、次のように動作します。
awk -vOFS='/' -F'/' '{$(NF-1)=sprintf("%s%04d", $(NF-2), FNR);
$NF=$(NF-1)".mp3"; print}' file
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0002/sn0002.mp3
http://twit.cachefly.net/audio/sn/sn0003/sn0003.mp3
http://twit.cachefly.net/audio/sn/sn0004/sn0004.mp3
http://twit.cachefly.net/audio/sn/sn0005/sn0005.mp3
http://twit.cachefly.net/audio/sn/sn0006/sn0006.mp3
http://twit.cachefly.net/audio/sn/sn0007/sn0007.mp3
http://twit.cachefly.net/audio/sn/sn0008/sn0008.mp3
http://twit.cachefly.net/audio/sn/sn0009/sn0009.mp3
http://twit.cachefly.net/audio/sn/sn0010/sn0010.mp3
http://twit.cachefly.net/audio/sn/sn0011/sn0011.mp3
http://twit.cachefly.net/audio/sn/sn0012/sn0012.mp3
http://twit.cachefly.net/audio/sn/sn0013/sn0013.mp3
http://twit.cachefly.net/audio/sn/sn0014/sn0014.mp3
http://twit.cachefly.net/audio/sn/sn0015/sn0015.mp3
http://twit.cachefly.net/audio/sn/sn0016/sn0016.mp3
http://twit.cachefly.net/audio/sn/sn0017/sn0017.mp3
http://twit.cachefly.net/audio/sn/sn0018/sn0018.mp3
http://twit.cachefly.net/audio/sn/sn0019/sn0019.mp3
http://twit.cachefly.net/audio/sn/sn0020/sn0020.mp3
http://twit.cachefly.net/audio/sn/sn0021/sn0021.mp3
http://twit.cachefly.net/audio/sn/sn0022/sn0022.mp3
http://twit.cachefly.net/audio/sn/sn0023/sn0023.mp3
http://twit.cachefly.net/audio/sn/sn0024/sn0024.mp3
http://twit.cachefly.net/audio/sn/sn0025/sn0025.mp3
http://twit.cachefly.net/audio/sn/sn0026/sn0026.mp3
http://twit.cachefly.net/audio/sn/sn0027/sn0027.mp3
http://twit.cachefly.net/audio/sn/sn0028/sn0028.mp3
http://twit.cachefly.net/audio/sn/sn0029/sn0029.mp3
http://twit.cachefly.net/audio/sn/sn0030/sn0030.mp3
http://twit.cachefly.net/audio/sn/sn0031/sn0031.mp3
http://twit.cachefly.net/audio/sn/sn0032/sn0032.mp3
http://twit.cachefly.net/audio/sn/sn0033/sn0033.mp3
http://twit.cachefly.net/audio/sn/sn0034/sn0034.mp3
http://twit.cachefly.net/audio/sn/sn0035/sn0035.mp3
http://twit.cachefly.net/audio/sn/sn0036/sn0036.mp3
http://twit.cachefly.net/audio/sn/sn0037/sn0037.mp3
答え2
#!/bin/bash
echo "Enter File you want to read"
read file
i=0;
if [ -f $file ]
then
echo "file is avalible"
while read -r line
do
echo "$line" | sed "s/http:\/\/twit.cachefly.net\/audio\/sn\/sn0001\/sn0001.mp3/http:\/\/twit.cachefly.net\/audio\/ sn\/sn000$i\/sn000$i.mp3/g"
((i++))
done<$file
else
echo "file is not abalible"
fi
答え3
シーケンスが1から548まで続くと仮定すると、ファイルを再生成する方が簡単になります。
$ cat regen.sh
#!/bin/bash
for i in $(seq -w 1 548); do
echo "http://twit.cachefly.net/audio/sn/sn0${i}/sn0{$i}.mp3"
done
$ bash regen.sh > newfile
$ cat netFile
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0002/sn0002.mp3
http://twit.cachefly.net/audio/sn/sn0003/sn0003.mp3
http://twit.cachefly.net/audio/sn/sn0004/sn0004.mp3
...
http://twit.cachefly.net/audio/sn/sn0548/sn0548.mp3