sed regex cannot get first match -


i give up... of following

15 sep 1605.00 (spx1530u1605-e),0.25,0.0,0.05,0.10,0,87 

i want extract number 1530 out of blob. "spx" can combination of capital letters [a-z] , varies in length, (e.g. goog, fb). there capital letter following number, in "u" in example.

below gets second number, 1605. i'm @ loss on how extract 1530.

echo "15 sep 1605.00 (spx1530u1605-e),0.0,0.0,266.10,284.60,0,0" | \ gsed -r 's/.*[a-z]([0-9].*)[-][a-z].*/\1/g' 

it acceptable perform operation on string "spxw1530i1605-e" rather entire line.

usually grep tool of choice when want extract data. can use gnu grep, offers perl compatile regular expression when pass -p option:

grep -op '\([a-z]+\k[0-9]+' file 

we searching literal ( followed 1 or more capital (ascii) letters. using \k cleans match buffer. (nice, isn't it?) following numbers final match.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -