1개의 텍스트 파일 콘텐츠를 여러 다른 파일에 복사해야 함

1개의 텍스트 파일 콘텐츠를 여러 다른 파일에 복사해야 함

소스 파일이 있어요blue01.환경(텍스트 파일)

복사해야 해텍스트이 파일에 복사하여 아래의 모든 파일에 붙여넣고 저장합니다.원래 이름으로.

blue02.environment
yellow01.environment
yellow02.environment
yellow03.environment
purple01.environment
purple02.environment
...

누군가 내가 사용할 수 있는 배치 명령을 알려줄 수 있나요?

답변1

이 시도:

#!/bin/bash

# the file you want the content to be copied
master=/your_dir/master_file

# get the content
content="$(cat $master)"

# loop the files .environment
for file in /your_dir/*.environment; do 
  # if the file is not the master file copy the content
  [ "$file" != "$master" ] && echo "$content" > "$file"
done

답변2

이건 어때?:

rem // Define constants here:
set "_ROOT=." & rem // (path to root directory; `.` is current, `%~dp0.` is batch file parent)
set "_MASK=*.environment" & rem // (pattern to match files to process)
set "_MASTER=blue01.environment" & rem // (name of master file)

rem // Change to root directory:
pushd "%_ROOT%" && (
    // Iterate over all matching files:
    for %%I in ("%_MASK%") do @(
        rem // Exclude master file to be overwritten:
        if /I not "%%~nxI" == "%_MASTER%" (
            rem // Copy master file onto current file:
            copy /Y "%_MASTER%" "%%~I" > nul
        )
    )
    rem // Return from root directory:
    popd
)

관련 정보