Sunday, April 7, 2013

Extracting Numerical values from a string

1)  Cutting numerals from a string
        sed 's/[^0-9]*//g'
  
    For example:
                           Hello world my name is 1234abcd
        Output      : 1234



2)  Extracting First number from a string
        sed 's/[^0-9.]*\([0-9.]*\).*/\1/'
  
     For example: Hello 123 world, my name is 1234abcd
            output    : 123   
 

No comments:

Post a Comment