Split string and numeric with perl
Hi experts,
I have a file contains this line: Mem: 906292k total, 873656k used, 32636k free, 164852k buffers ------------ I have made a perl script to split that lines @top_file = <JX>; foreach my $regex (@top_file){ if ($regex =~ /Mem: (.*)$/){ @data = split(/,\s/, $regex); the result is : 906292k total873656k used32636k free164852k buffers My question, how to delete all string k total, k used, k free, k buffers, so I just have a number e.g. 906292 873656 32636 164852. Many thanks for your help. |
if Perl is not a must, here's awk for you
Code:
$ awk '{for(i=2;i<=NF;i+=2)printf "%s ",$i+0}' file |
Code:
grep -oP "\d*" ??? |
Quote:
@kariageken: Rather than slurp the whole file in at once, I would read it in line by line. In terms of removing everything but the digits, I would do that using map as I did the split. Here's an example: Code:
#!/usr/bin/env perl |
Hai All, thank you for your reply and appreciate for your solution
Regards Kariagekun |
All times are GMT -5. The time now is 06:52 AM. |