Ich habe eine Quelldateiblue01.umgebung(Textdatei)
Ich muss kopierender Textin dieser Datei und fügen Sie es in alle untenstehenden Dateien ein, speichern Sie sie jedochmit ihrem ursprünglichen Namen.
blue02.environment
yellow01.environment
yellow02.environment
yellow03.environment
purple01.environment
purple02.environment
...
Kann mir jemand einen Batch-Befehl nennen, den ich verwenden kann?
Antwort1
Versuche dies:
#!/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
Antwort2
Was ist damitBatchdatei:
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
)