1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

サクラエディタのGrep機能を複数ワードまとめて実行できるVSBファイルを作ってみた

Last updated at Posted at 2021-09-12

はじめに

大量のフォルダ・ファイルから必要なワードを検索するのにサクラエディタのGrep機能はとても重宝しますよね。
ただ、Grepしたい検索ワードが複数存在する場合に、1回1回手動でGrepするのは手間だなと思っていたので、複数ワードまとめてGrepできるプログラムを作成してみました。

正規表現で検索条件を指定すればいいのではという指摘はNGで

作ったもの

  • VBScriptでサクラエディタをコマンドラインで実行させるスクリプト
  • Grep検索条件リストファイルに定義した検索ワードを1行ずつ取得しGrepを実施
    • 例)ファイルの内容が下記の場合、ワード1ワード2ワード3の順でGrep処理を実行
      • ワード1
      • ワード2
      • ワード3
  • 実行結果は指定したファイルにまとめて出力する。

ソースコード

Grep一括実行.vbs
'*********************************************************
'[概要]
' Grep検索条件リストファイルに定義した検索ワードを1行ずつ取得しGrepを実施する
' Grep結果は指定したファイルにまとめて出力する
'*********************************************************
Option Explicit

Dim strLine
Dim WshShell: Set WshShell = Wscript.CreateObject("Wscript.Shell")
Dim objFIleSys: Set objFileSys = Wscript.CreateObject("Scripting.FileSystemObject")

Dim strReadFilePath: strReadFilePath = "C:\Users\xxxxx\Desktop\work\input.txt"'Grep検索条件リストファイル
Dim inputPath: inputPath = "C:\Users\xxxxx\Desktop\work\Grep対象フォルダ"'Grep対象フォルダ
Dim outputFilePath: outputFilePath = "C:\Users\xxxxx\Desktop\work\OutputFile.txt"'Grep結果出力先
Dim charCode: charCode ="99" '文字コードのオプション
Dim searchOption: searchOption = "SU" '検索条件のオプション

Dim objReadStream: Set objReadStream = objFileSys.OpenTextFile(strReadFilePath, 1)

WshShell.CurrentDirectory = "C:\Program Files (x86)\sakura"

Do Until objReadStream.AtEndOfStream = True
  'Grep検索条件リストの用語を1行ずつ取得し、Grepを実行
  strLine = objReadStream.ReadLine
  WshShell.Run("cmd /c sakura.exe -GREPMODE -GCODE=" & charCode & " -GKEY=" & """" & strLine & """" & " -GFOLDER=" & inputPath & " -GOPT=" & searchOption & " >>" & outputFilePath)
  WScript.sleep(1500)
LOOP

objReadStream.Close

Set objFileSys = Nothing

msgbox "end"

参考サイト

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?