开发者

How to extract data from a file

开发者 https://www.devze.com 2023-02-05 03:37 出处:网络
Hey everyone, I have a file with info like the below. I want to extract the numbers out of the records. Can some one give me an awk or a sed oneliner if possible? Maybe out put to a file? This would r

Hey everyone, I have a file with info like the below. I want to extract the numbers out of the records. Can some one give me an awk or a sed oneliner if possible? Maybe out put to a file? This would really help me out. I am on ubuntu so I have linux utilities.

Thanks a lot.

<product_id>101747</product_id>
<product_id>2847549</product_id>
<product_id>149833</product_id>
<product_id>123380</product_id>
<product_id>66334</product_id>
<product_id>66475</product_id>
<product_id>123387</product_id>
<product_id>6266040</product_id>
<product_id>3480755</product_id>
<product_id>6529572</product_id>
&l开发者_StackOverflowt;product_id>22852</product_id>


Python oneliner:

python -c "import re;print('\n'.join(re.findall('([0-9]+)',open('infile.txt').read())))" > outfile.txt

Change infile.txt and outfile.txt.

Example output:

101747
2847549
149833
123380
66334
66475
123387
6266040
3480755
6529572
22852
0

精彩评论

暂无评论...
验证码 换一张
取 消