我正在测试在文本文件中有设置的软件。 现在,我需要在〜100个文件中更改特定行。
我搜索了几个小时,并且已经接近解决方案。但是不知道如何完成它。
notepad ++中的解决方案会很好,但是我使用以下命令通过powershell进行了尝试:
# File to change
$file = *.dat
# Get file content and store it into $content variable
$content = Get-Content -Path $file
# Replace the line number 40 with "0"
$content[39] = '"0"'
# Set the new content
$content | Set-Content -Path $file
它更改了特定的行,但是它还在文件夹中的所有文件中添加了所有文件的数据。因此,在200行的情况下,文件现在有20000行。每个文件。
我要更改所有文件的行号40:
“ 0” 改成 “ 1”
因为其他行上有多个带有“ 0”的值,所以我只想在多个文件中更改第40行。