0
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?

More than 3 years have passed since last update.

Winodowsメモ帳でGrepするbat(再アップ)

Last updated at Posted at 2020-10-06

Windowsのメモ帳しか使えない環境で、log確認等をすることが多かったので
batファイルを作ってみた。

ほんとエディターツールってすばらしいよね。。。

zipファイル

zipファイルをダウンロード

使い方

①Greplist.txtと本batファイル準備する。

②Greplist.txtへGrepしたいワードを入れる。

③①のファイルをGrepしたいファイルの階層に格納する。
 ※サブフォルダにも対応しているので上位フォルダへ格納もOK

④Grep.batを実行する。
 ※Grepしたいファイルの拡張子を入力する。
  例:.txtの場合⇒txt  .logの場合⇒log

⑤Grep結果のファイルがデスクトップへ出力される。
 

出力イメージ

image.png

※内容説明
 ・starttime:実行した時間
 ・Grep keyword:Greplistに記載している検索キーワード
 ・該当のファイル名:行数:行内容
 ・endtime:終了した時間

ソースコード

Grep.bat
echo off


rem デスクトップへ[日付.log]でログの生成
set fname=%USERPROFILE%\Desktop\%date:~0,4%%date:~5,2%%date:~8,2%.log

:Start
set /p filetype="Grep対象ファイルの拡張子を入力して下さい[拡張子を入力]:"

echo 対象拡張子:.%filetype% 
:Select
set /p Check="以上の設定でGrepを始めます。よろしいですか?...[Y/N] "

if /i %Check%==Y Goto:GREP
if /i %Check%==YES Goto:GREP
if /i %Check%==N Goto:Start
if /i %Check%==NO Goto:Start

:GREP
echo starttime %date% %time% >> %fname%
echo; >> %fname%
echo Grep keyword >> %fname%
findstr -g:Greplist.txt Greplist.txt >> %fname%
echo; >> %fname%
echo; >> %fname%
findstr -i -s -n  -g:Greplist.txt *.%filetype% >> %fname%
echo; >> %fname%
echo endtime %date% %time% >> %fname%
echo; >> %fname%
echo; >> %fname%
pause

更新(2021/3/12)

拡張子設定後の確認ステップ追加[.拡張子]形式で表示。
出力結果の画像および内容について追記。
zip形式でダウンロード可能にしました。

0
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
0
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?