I have a line that looks like this:
"abcderwer 123123 10,200 asdfasdf iopjjop"
Now I want to extract the numbers following the pattern xx, xxx, where x is a number between 0-9. For instance. 10200. There must be five digits and must contain ",".
How can i do this?
thank
You can use grep:
grep
$ echo "abcderwer 123123 10,200 asdfasdf iopjjop" | egrep -o '[0-9]{2},[0-9]{3}' 10,200
In a pure bash:
pattern='([[:digit:]]{2},[[:digit:]]{3})' [[ $string =~ $pattern ]] echo "${BASH_REMATCH[1]}"
.
:
Bash
SO
, , - grep. : (globbing) find .
( ) . , $* ( script, set , ), :
$*
set
for token; do case $token in [0-9][0-9],[0-9][0-9][0-9] ) echo "$token" ;; esac done
, , sed.
$ echo abcderwer 123123 10,200 asdfasdf iopjjop | sed -ne 's/^.*\([0-9,]\{6\}\).*$/\1/p' 10,200
< input tr -cd [0-9,\ ] | tr \ '\012' | grep '^..,...$'
( tr , , . second tr , "" line, grep , , .)