중괄호 확장을 사용하여 일련의 파일을 만들려고 합니다. fileA1
가능한 모든 조합으로 파일을 만들고 싶습니다 fileZ100
( 와 유사 touch file[A..Z][1..100]
).
명령을 실행하면 touch $(printf "file%d " {1..100})
출력이 괜찮습니다.
file1 file15 file21 file28 file34 file40 file47 file53 file6 file66 file72 file79 file85 file91 file98
file10 file16 file22 file29 file35 file41 file48 file54 file60 file67 file73 file8 file86 file92 file99
file100 file17 file23 file3 file36 file42 file49 file55 file61 file68 file74 file80 file87 file93
file11 file18 file24 file30 file37 file43 file5 file56 file62 file69 file75 file81 file88 file94
file12 file19 file25 file31 file38 file44 file50 file57 file63 file7 file76 file82 file89 file95
file13 file2 file26 file32 file39 file45 file51 file58 file64 file70 file77 file83 file9 file96
file14 file20 file27 file33 file4 file46 file52 file59 file65 file71 file78 file84 file90 file97
내가 실행해도 마찬가지입니다 touch $(printf "file%c " {A..Z})
.
fileA fileC fileE fileG fileI fileK fileM fileO fileQ fileS fileU fileW fileY
fileB fileD fileF fileH fileJ fileL fileN fileP fileR fileT fileV fileX fileZ
나는 그것들을 결합하려고 시도했지만 touch $(printf "file%c%d " {A..Z}{1..100})
결과는 다음과 같습니다.
[...]
-bash: printf: Y2: invalid number
-bash: printf: Y4: invalid number
-bash: printf: Y6: invalid number
-bash: printf: Y8: invalid number
-bash: printf: Y10: invalid number
-bash: printf: Y12: invalid number
-bash: printf: Y14: invalid number
-bash: printf: Y16: invalid number
-bash: printf: Y18: invalid number
-bash: printf: Y20: invalid number
-bash: printf: Y22: invalid number
-bash: printf: Y24: invalid number
-bash: printf: Y26: invalid number
-bash: printf: Y28: invalid number
-bash: printf: Y30: invalid number
-bash: printf: Y32: invalid number
-bash: printf: Y34: invalid number
-bash: printf: Y36: invalid number
-bash: printf: Y38: invalid number
-bash: printf: Y40: invalid number
-bash: printf: Y42: invalid number
-bash: printf: Y44: invalid number
-bash: printf: Y46: invalid number
-bash: printf: Y48: invalid number
-bash: printf: Y50: invalid number
-bash: printf: Y52: invalid number
-bash: printf: Y54: invalid number
-bash: printf: Y56: invalid number
-bash: printf: Y58: invalid number
-bash: printf: Y60: invalid number
-bash: printf: Y62: invalid number
-bash: printf: Y64: invalid number
-bash: printf: Y66: invalid number
-bash: printf: Y68: invalid number
-bash: printf: Y70: invalid number
-bash: printf: Y72: invalid number
-bash: printf: Y74: invalid number
-bash: printf: Y76: invalid number
-bash: printf: Y78: invalid number
-bash: printf: Y80: invalid number
-bash: printf: Y82: invalid number
-bash: printf: Y84: invalid number
-bash: printf: Y86: invalid number
-bash: printf: Y88: invalid number
-bash: printf: Y90: invalid number
-bash: printf: Y92: invalid number
-bash: printf: Y94: invalid number
-bash: printf: Y96: invalid number
-bash: printf: Y98: invalid number
-bash: printf: Y100: invalid number
-bash: printf: Z2: invalid number
-bash: printf: Z4: invalid number
-bash: printf: Z6: invalid number
-bash: printf: Z8: invalid number
-bash: printf: Z10: invalid number
-bash: printf: Z12: invalid number
-bash: printf: Z14: invalid number
-bash: printf: Z16: invalid number
-bash: printf: Z18: invalid number
-bash: printf: Z20: invalid number
-bash: printf: Z22: invalid number
-bash: printf: Z24: invalid number
-bash: printf: Z26: invalid number
-bash: printf: Z28: invalid number
-bash: printf: Z30: invalid number
-bash: printf: Z32: invalid number
-bash: printf: Z34: invalid number
-bash: printf: Z36: invalid number
-bash: printf: Z38: invalid number
-bash: printf: Z40: invalid number
-bash: printf: Z42: invalid number
-bash: printf: Z44: invalid number
-bash: printf: Z46: invalid number
-bash: printf: Z48: invalid number
-bash: printf: Z50: invalid number
-bash: printf: Z52: invalid number
-bash: printf: Z54: invalid number
-bash: printf: Z56: invalid number
-bash: printf: Z58: invalid number
-bash: printf: Z60: invalid number
-bash: printf: Z62: invalid number
-bash: printf: Z64: invalid number
-bash: printf: Z66: invalid number
-bash: printf: Z68: invalid number
-bash: printf: Z70: invalid number
-bash: printf: Z72: invalid number
-bash: printf: Z74: invalid number
-bash: printf: Z76: invalid number
-bash: printf: Z78: invalid number
-bash: printf: Z80: invalid number
-bash: printf: Z82: invalid number
-bash: printf: Z84: invalid number
-bash: printf: Z86: invalid number
-bash: printf: Z88: invalid number
-bash: printf: Z90: invalid number
-bash: printf: Z92: invalid number
-bash: printf: Z94: invalid number
-bash: printf: Z96: invalid number
-bash: printf: Z98: invalid number
-bash: printf: Z100: invalid number
그럼... 올바른 정규식은 무엇인가요? 파이프를 사용해야 하나요?
답변1
그래서 여기 있습니다:
printf "file%c%d " {A..Z}{1..100}
중괄호 확장은 A1
, A2
, A3
... , 와 같은 Z99
문자열을 생성합니다 Z100
. 그런 다음 첫 번째 for , 두 번째 for , 세 번째 for 등을 사용하여 형식 지정자 sum 과 일치 printf
시켜 봅니다 .%c
%d
%c
%d
%c
그러나 %d
숫자를 기대했지만 A2
1이 아니므로 오류가 발생합니다.
%c%d
A
, 1
, A
, ... 와 같은 인수를 별개의 인수로 예상 2
하지만 이는 중괄호 확장으로 생성하기 어렵습니다.
중괄호 확장은 이미 영숫자 시퀀스를 결합하므로 printf "file%s " {A..Z}{1..100}
확장 결과를 직접 사용할 수 있습니다. 아니면 그냥 echo file{A..Z}{1..100}
.
아니면 좀 더 직접적인 버전플러머의 답변가지다.
답변2
당신은 그것을 사용할 수 있습니다버팀대 확장직접적으로 touch
:
touch file{A..Z}{1..100}