掌上百科 - PDAWIKI

 找回密码
 免费注册

QQ登录

只需一步,快速开始

查看: 555|回复: 2

[教程] powergrep 008

[复制链接]

该用户从未签到

发表于 2017-11-20 23:05:26 | 显示全部楼层 |阅读模式
本帖最后由 zhu1234 于 2017-12-12 00:27 编辑
% |7 N9 {7 c& s
5 F9 Q1 n; Z9 ^) I8 b, K% tSplit Logs into Files with a Certain Number of Entries
2 m& H. Z2 L# W
' ?& B( K  n; J! @. Z9 [8 s$ j  lDealing with large log files is often cumbersome. With PowerGREP you can easily split logs into separate files with a specific number of entries per log. E.g. splitlog0.txt would have the entries 0 to 999, splitlog1.txt has entries 1,000 to 1,999, and so on. You can put all the entries from the original log or logs into the target files, or you can extract only those entries that you're interested in.* V0 l9 q  j, Z  ]  @% y1 P# Y

% r5 k% x: g, U3 X: c1 cSelect the log files you want to split in the File Selector.
6 a: y# U5 ]3 A3 P* |* l" r( ]Start with a fresh action.
& R6 Y, {4 I. f9 K' xSet the action type to "split files".
% z7 i& H+ w, i9 Q) |; mIn the "file sectioning" list, select "line by line, including line breaks". This works for logs that use one line for each entry.) r" Q- a2 q" \/ w; X7 D
Turn on the option "split whole sections". This makes sure lines will be extracted as a whole into the target files.$ _6 N  n3 }% M- O% G" o
If you want all log entries to be in the split files, enter the regular expression . into the search box, and make sure "dot matches newlines" is off. This puts any line that is not blank into the target files. If you want only certain lines, enter a search term or regex that (partially) matches the log entries you want to extract. E.g. search for ^Error to extract only those entries starting with the word "Error".
: L6 @; W0 w- R2 V; xIn the Target File box, enter something along the lines of c:\logs\splitlog%MATCHNZ:/1000%.txt to specify the target path. The match placeholder %MATCHNZ:/1000% takes the number of the match counting from zero, and divides it by 1000. This results in 0 for the first 1,000 matches, 1 for the second 1,000 matches, and so on. If you want the first log file to be number one, use %MATCHNZ:/1000+1%. Match placeholders use integer arithmetic that is calculated strictly from left to right. If you expect to have more than 10 but less than, say, 100 log files, you can pad the number in the target file name to have two digits by using %MATCHNZ:/1000:2Z% or %MATCHNZ:/1000+1:2Z% as the placeholder. 2Z means to pad with zeros to make the placeholder have at least two digits.
. M, Y" Z1 k- a/ E: s$ d; X2 Y- DSet "between collected text" set to "nothing". Since we're collecting whole lines including line breaks, there's no need to add more delimiters.5 u& F" S. c1 r+ }
Set the backup file options as you like them.
" O( R7 w& [/ S. q: J, eClick the Quick Split button to split the file. Use this button instead of Split Files. Otherwise PowerGREP will waste a lot of time and memory to display your entire log files on the Results panel.! Y4 l% G$ e% w% e& J+ p
Splitting files does not delete the original files. It may overwrite original files if the Target File for one or more search matches is a file that is searched through. When splitting files PowerGREP does not write the final target files until the action has completed. Overwriting source files won't alter the search matches.
# x4 C# w- e  L8 {. T& C( o0 J: A* f1 e5 t! U4 S/ P8 O4 u# T
This action is available in the PowerGREP5.pgl library as "Logs: Split Logs into Files with a Certain Number of Entries".* f: Q$ n+ N* g4 N8 L
8 n# B; A- s  D, J
Recombining Log Files& O( l" U7 {& b+ E
, Z, l  v  c7 F! A/ e! V2 I
The above example can also be used to recombine log files. Say you previously split your logs into files with 1,000 entries and deleted the original logs. Now want the logs to be split into files with 2,500 entries each.
' j9 b8 G& s# }! H0 X' W, o# w
  C; ~' z4 s. ~' D7 V3 [8 VFollow the exact same steps as above. In the first step, select all the previously split log files. In step 7, use %MATCHNZ:/2500% as the placeholder.
- O& v/ y- e6 I$ L# K
% {3 @1 i0 D. mIn PowerGREP, a "split files" action can put search matches from one file into different target files. It can also put search matches from different files into the same target file. In our example, all matches from old logs 1 and 2 (with 1,000 entries each) are saved into new log number 1. The first 500 matches from old log number 3 are saved into new log number 1, and the remaining 500 are saved into old log number 2.6 M. U3 G) ^3 I

& f* B2 v3 L* Y1 o: Q' P/ PThe "order of collected matches" drop-down list determines the order in which matches (log entries in this case) from different files are written when a "split files" action calculates the same target file path from matches from multiple files. This is important if you want your log entries in the combined file to have the same order as in the original files. If your original log files put the log entries in order if you sort the files alphabetically by name, then choose "sort files Alphabetically A..Z". If the time stamp on the log files puts the files in the correct order (e.g. the time stamp on each log file is the time the last entry was written) then you can choose "oldest file to newest file".
9 y/ C; H+ V0 @! M* N9 t/ y1 {% d* x( ?$ G1 N! G( ^; g
Discuss$ g& ?' J+ H5 |+ [4 H5 K+ P8 L+ M
6 ~+ O% ?5 a4 {' h. I/ X3 j
Start or join the conversation on the topic "Docs: Split Logs into Files with a Certain Number of Entries" in PowerGREP's discussion forum.
  • TA的每日心情
    开心
    2018-3-7 10:40
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2017-12-21 19:50:51 | 显示全部楼层
    what???what???what???what???  what???what???what???

    评分

    1

    查看全部评分

    您需要登录后才可以回帖 登录 | 免费注册

    本版积分规则

    小黑屋|手机版|Archiver|PDAWIKI |网站地图

    GMT+8, 2024-4-25 18:12 , Processed in 0.053932 second(s), 9 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2023, Tencent Cloud.

    快速回复 返回顶部 返回列表