需要使用批处理文件复制特定字符串之前的行 [英] Need to copy the lines just before a particular string using batch file

查看:38
本文介绍了需要使用批处理文件复制特定字符串之前的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的文件:

I have a file like this:

Executing resource: D:\waste2\SPC\depks_rtl_teller_custom.spc   
Executing resource: D:\waste2\SPC\ifpks_msg_incoming_cluster.spc  
Failed to execute:   
Executing resource: D:\waste2\SQL\casapks_batch.sql  
Failed to execute:  
Executing resource: D:\waste2\SQL\depks_decbatop_kernel.sql  
Executing resource: D:\waste2\SQL\depks_services.sql  
Failed to execute:    

我需要一个批处理文件或perl脚本或ANT脚本来选择字符串"Failed to execute:"前面的所有行并将其复制到新文件.只是我需要在新文件中的失败文件列表.请协助.

I need a batch file or perl script or ANT script to pick all the lines just in front of the string "Failed to execute:" and copy to a new file. Simply the failed file list I need in a new file. Please assist.

推荐答案

使用perl,您可以执行以下操作:

With perl, you could do something like:

while(<>) {
  print $prev if /^Failed to execute:/;
  $prev = $_;
}

要直接从外壳执行,可以使用以下命令

To execute directly from your shell, you can use the following command

perl -ne 'print $prev if /^Failed to execute:/; $prev=$_' path/to/your/file

这篇关于需要使用批处理文件复制特定字符串之前的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆