需要将 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
)

相关内容