2012-02-15 2 views
2

私はcURLを使用してローカルフォルダにファイルをダウンロードしています。私はこのようなルックスを使用していますコマンド:URLの一部をcURLで同時にインクリメントする方法を教えてください。

curl -O http://example.com/example/file[001-030]_file_[1-30]_eng.ext 

私は番号が同じ時間(「file001_file_1_eng.ext」)でインクリメントしたいので、彼らは一致します。代わりに、これはネストされたループのように動作し、コマンドは既存のファイルと共にフォルダに空のファイルの束を書き込んでいます。だから私は得る:

file001_file_1_eng.ext 
file001_file_2_eng.ext <--- file doesn't exist 
file001_file_3_eng.ext <--- file doesn't exist 

など...だから

、私は彼らが正しい方法でインクリメントする取得する方法を疑問に思っています。私はこの出力を取得しているよ

example.com/example/file008_file_1_eng.text 
example.com/example/file009_file_2_eng.text 
example.com/example/file010_file_3_eng.text 
example.com/example/file011_file_4_eng.text 
example.com/example/file012_file_5_eng.text 
example.com/example/file013_file_6_eng.text 
example.com/example/file014_file_7_eng.text 
example.com/example/file015_file_8_eng.text 
example.com/example/file016_file_9_eng.text ... and so on. 
+0

ここでループ内の数字をどのように作成するのですか? –

答えて

4

私はあなたがforループ使用したいかもしれないと思う:このループによって

#!/bin/bash 
for i in {0..30}; do 
    printf -v url "http://example.com/example/file%03d_file_%d_eng.text" $i $i 
    curl -O $url 
done 

を、urlはあなたが取得する必要があります次のもの:

http://example.com/example/file000_file_0_eng.text 
http://example.com/example/file001_file_1_eng.text 
http://example.com/example/file002_file_2_eng.text 
http://example.com/example/file003_file_3_eng.text 
http://example.com/example/file004_file_4_eng.text 
http://example.com/example/file005_file_5_eng.text 
http://example.com/example/file006_file_6_eng.text 
http://example.com/example/file007_file_7_eng.text 
http://example.com/example/file008_file_8_eng.text 
http://example.com/example/file009_file_9_eng.text 
http://example.com/example/file010_file_10_eng.text 
http://example.com/example/file011_file_11_eng.text 
http://example.com/example/file012_file_12_eng.text 
http://example.com/example/file013_file_13_eng.text 
http://example.com/example/file014_file_14_eng.text 
http://example.com/example/file015_file_15_eng.text 
http://example.com/example/file016_file_16_eng.text 
http://example.com/example/file017_file_17_eng.text 
http://example.com/example/file018_file_18_eng.text 
http://example.com/example/file019_file_19_eng.text 
http://example.com/example/file020_file_20_eng.text 
http://example.com/example/file021_file_21_eng.text 
http://example.com/example/file022_file_22_eng.text 
http://example.com/example/file023_file_23_eng.text 
http://example.com/example/file024_file_24_eng.text 
http://example.com/example/file025_file_25_eng.text 
http://example.com/example/file026_file_26_eng.text 
http://example.com/example/file027_file_27_eng.text 
http://example.com/example/file028_file_28_eng.text 
http://example.com/example/file029_file_29_eng.text 
http://example.com/example/file030_file_30_eng.text 
+0

ありがとう:@jcollado、私はまだURLの数字が一致しないという事実に問題があります。例:http://example.com/example/file035_file_1_eng.text私はこれを修正するために新しい変数を作成しようとしましたが、正しく機能するようには見えません。多分、私は軌道に乗っていません。 – Jordan

+0

@honestinjun答えのコードで、私はそのような振る舞いは見ません。あなたが間違ったファイル名を取得するために何を実行しているのかを詳しく説明できますか? – jcollado

+0

申し訳ありませんが、私の返信は明確ではありませんでした。情報を取得しているURLはexample.com/example/file035_file_1_eng.txtです。しかし、あなたの答えでは、$ iを使用するとexample.com/example/file031_file_1_eng.textが得られます。 2つの異なる変数を使用して両方を増分する方法はありますか? – Jordan

関連する問題