0

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

1
  • 1
    grep '[0-9]' filename should work. Then save the output to whatever file you want. (awk could do the same pretty easily.) I'm assuming the file is as you show - the non-numeric lines have no numbers in them. If this isn't the case, you could tweak the search. Commented Nov 12, 2011 at 18:18

2 Answers 2

1

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  
Sign up to request clarification or add additional context in comments.

Comments

0

cat filename | grep "[0-9]"

1 Comment

You can do away with cat and simply do grep <pattern> filename

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.