0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

特定の文字列を含む行を削除する PowerShell

Posted at

特定の文字列を含む行を削除する PowerShell

Microsoft Windows [Version 10] で確認。

LineExclusion.ps1
#===================#
# LineExclusion.ps1 #
#===================#
### 対象PATH ###
$path = "C:\Users\Desktop\test\json"

### Grep対象の文字列 ###
$str = """DELETE_FLG"":1"

### ファイル一覧取得 ###
$childItems = Get-ChildItem -Path $path | Select-String -Pattern $str | % { $_.Path }

foreach($item in $childItems)
{
    ### ファイル名の定義 ###
    $itemtmp = $item + ".tmp"
    $itemold = $item + ".old"

    ### 該当行を削除 ###
    sls -NotMatch $str $item | %{$_.Line} > $itemtmp
    echo "処理中:$item"

    ### ファイル名の操作 ###
    Rename-Item -Path $item -NewName $itemold
    Rename-Item -Path $itemtmp -NewName $item
}

ファイルから「"DELETE_FLG":1」を含む行を削除する PowerShell Program を作成しました。フォルダ一括で処理します。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?