marc
marc

Reputation: 971

Text processing using bash

I have a vmstat dump file that has the header and values in this format

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------  
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st  
12  0 5924396 20810624 548548 935160    0    0     0     5    0    0 60  5 34  0  0  
12  0 5924396 20768588 548548 935160    0    0     0     0 1045 1296 99  0  0  0  0  
12  0 5924396 20768968 548548 935452    0    0     0    32 1025 1288 100  0  0  0  0  
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------  
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st  
 4  0 5924396 20768724 548552 935408    0    0     0    92 1093 1377 33  0 67  0  0  

I'm writing a script in bash that extracts just the lines containing lines with numbers i.e. values and remove all lines containing the alphabet. How do I do that

Upvotes: 0

Views: 385

Answers (2)

If you need a lines with numbers and tabs\spaces only, grep -P "^[0-9\ \t]*$" should helps you.

$> cat ./text | grep -P "^[0-9\ \t]*$"
12  0 5924396 20810624 548548 935160    0    0     0     5    0    0 60  5 34  0  0  
12  0 5924396 20768588 548548 935160    0    0     0     0 1045 1296 99  0  0  0  0  
12  0 5924396 20768968 548548 935452    0    0     0    32 1025 1288 100  0  0  0  0  
 4  0 5924396 20768724 548552 935408    0    0     0    92 1093 1377 33  0 67  0  0  

Upvotes: 1

LisztLi
LisztLi

Reputation: 242

cat filename | grep "[0-9]"

Upvotes: 0

Related Questions