批处理脚本在文本文件中查找正则表达式并在另一个文本文件中逐行写入

时间:2015-03-09 16:38:12

标签: regex batch-file

我的文本文件包含以下行:

Successfully started load asymmetric-song-851:bqjob_r069b9290_0000014bfebbdfa9_1
Successfully started load asymmetric-song-851:bqjob_r76eb714e_0000014bfebbf0de_1                                  BigQuery error in load operation: Error processing job 'asymmetric-song-851:bqjob_r7853a02a_0000014bfebc0247_1':
Not found: URI gs://brillio_buck/Week/game_activity_android_2015-01-23_to_2015-01-25.tsv 
Some random text ...,,,, Some other random text
Successfully started load asymmetric-song-851:bqjob_r7d6c8bc3_0000014bfebc0d8f_1 
Successfully started load asymmetric-song-851:bqjob_r110f9c79_0000014bfebc19fc_1
Successfully started load asymmetric-song-851:bqjob_r56873b54_0000014bfe9caeb7_1  
Successfully started load asymmetric-song-851:bqjob_r0edb7092_0000014bfe9cbb8c_1 

我只想在其他文本文件中使用诸如bqjob_r0edb7092_0000014bfe9cbb8c_1这样的作业。所以我的输出文件应该是:

bqjob_r069b9290_0000014bfebbdfa9_1
bqjob_r76eb714e_0000014bfebbf0de_1
bqjob_r7853a02a_0000014bfebc0247_1
bqjob_r7d6c8bc3_0000014bfebc0d8f_1
bqjob_r110f9c79_0000014bfebc19fc_1
bqjob_r56873b54_0000014bfe9caeb7_1
bqjob_r0edb7092_0000014bfe9cbb8c_1

1 个答案:

答案 0 :(得分:1)

您可以使用grep -o

grep -o 'bqjob_r[^[:blank:]]*_[0-9]' file
bqjob_r069b9290_0000014bfebbdfa9_1
bqjob_r76eb714e_0000014bfebbf0de_1
bqjob_r7853a02a_0000014bfebc0247_1
bqjob_r7d6c8bc3_0000014bfebc0d8f_1
bqjob_r110f9c79_0000014bfebc19fc_1
bqjob_r56873b54_0000014bfe9caeb7_1
bqjob_r0edb7092_0000014bfe9cbb8c_1