Batch script to find a regex in a text file and write it line by line in another text file

纵然是瞬间 提交于 2020-01-17 12:26:33

问题


My text file accommodates these lines:

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 

I want only jobids such as bqjob_r0edb7092_0000014bfe9cbb8c_1 in some other text file.So my output file should be as:

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:


You can use 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


来源:https://stackoverflow.com/questions/28947240/batch-script-to-find-a-regex-in-a-text-file-and-write-it-line-by-line-in-another

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!