bash - How to retrieve digits including the separator "." -
i using grep string this: ans_length=266.50 use sed digits: 266.50
this full command: grep --text 'ans_length=' log.txt | sed -e 's/[^[[:digit:]]]*//g'
the result : 26650
how can line changed result still shows separator: 266.50
you don't need grep if going use sed. use sed' // match lines need print.
sed -n '/ans_length/s/[^=]*=\(.*\)/\1/p' log.txt -nsuppress printing of lines not match/ans_length/- using captured group print value next
=sign. pflag @ end allows print lines matches our//.
if grep happens support -p option can do:
grep -op '(?<=ans_length=).*' log.txt (?<=...)look-behind construct allows match lines need. requires-poption-oallows print value part.
Comments
Post a Comment