.txt ファイルを保存するフォルダーが 2 つあります。
Folder1 has File1.txt
Folder2 has File2.txt
の内容File1.txt
Some text
ABCD123X Execute String1
Some text
の内容File2.txt
String1 Procedure
ABCD
EFGH
出力:
Some text
ABCD123X Execute String1
ABCD
EFGH
Some text
要件 :
File2.txt で'Execute String1'
パターンを見つけたら、File1.txt 自体を展開したい'String1 Procedure'
これは私がこれまでに試したことです:
$string1 = $null
gc $file.fullname | ? {
if ($_ -match "(.*)EXECUTE(\s)([A-Za-z_0-9][^ |^,]*)" -and $_ -notmatch "^\/\/*") {
$string1 = $matches[3]
} elseif ($string1 -ne $null) {
get-content file.fullname, $string1.fullname | out-file $combined.txt
# This is appending string1.txt file at end of file.txt
}
}
string1.txt を file.txt の末尾ではなく、見つけた場所のすぐ下の位置に追加する方法が必要です。このような :
Some text
ABCD123X Execute String1
ABCD
EFGH
Some text