2012-02-15 4 views
2

로컬 폴더에 파일을 다운로드 할 때 cURL을 사용하고 있습니다. 나는이 같은 모습을 사용하고 명령 :URL의 일부를 동시에 증가 시키려면 어떻게합니까?

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가 표시됩니다. 두 개의 다른 변수를 사용하고 둘 다 증가시키는 방법이 있습니까? – Jordan

관련 문제