我有一个类似下面的日志文件,我想将匹配的搜索结果复制到一个新文件中。我正在尝试搜索下面列出的所有项目条形码 它们都以312600开头,包括将数字包裹到下一行的那些,并将这些条形码复制到另一个文件中。
感谢您的帮助
7/9/2012,11:09:14 Station: 0079 Request: Sequence #: 54 Command: Charge Item
Part B
station login user access:CIRC station library:MAIN station login clearance:NO
NE station user's user ID:MAINCIRC item ID:31260016399431 user ID:21660009335
807 Client type: see client_types.h for values:3 rs:Y jz:1 user block
override:YES Max length of transaction response:3000000
7/9/2012,11:19:15 Station: 0079 Request: Sequence #: 56 Command: Charge Item
Part B
station login user access:CIRC station library:MAIN station login clearance:NO
NE station user's user ID:MAINCIRC item ID:31260016121751 user ID:21760000705
807 Client type: see client_types.h for values:3 rs:Y jz:1 user block
override:YES Max length of transaction response:3000000
7/27/2012,07:45:45 Station: 0040 Request: Sequence #: 10 Command: Renew User
Part B
station login user access:PUBLIC station login clearance:NONE station
library:MAIN Client type: see client_types.h for values:1 item ID:312600161880
08 call number:F HOF copy number:2 user ID:25210000905805 WWW CGI program
name:93 transaction in goback unless "N":N Wt:ELib
答案 0 :(得分:0)
尝试使用 grep 或 egrep ,如下所示:
grep -e '312600\d*' -o log_file > output_file
您的代码段输出:
31260016399431
31260016121751
312600161880
使用 pcregrep ,你可以包含回车符,但我还没看到如何删除它们(我看到了一些关于使用 tr 的内容,但我没有现在有时间调查一下。)
pcregrep -Moe '312600[\n\d]*' log_file > output_file
31260016399431
31260016121751
312600161880
08
不幸的是,这仍然存在换行符,但也许您可以通过其他方式来解决此问题。