EverythingRightPlace
EverythingRightPlace

Reputation: 1197

regex/sed example to spot numbers

I have an input like this

this  
is  
3some  
137 test  
text

and want to extract just the numbers at the beginning.

I tried:

sed 's/![0-9]{1,}.*//1'

but this isn't cutting anything.

Thx in advance, I am pretty new to Linux at all but this page already helped me a lot!

Upvotes: 1

Views: 414

Answers (1)

BeniBela
BeniBela

Reputation: 16907

Use grep to extract stuff:

grep -oE '^[0-9]+'

o to get only the matched part instead of the whole line, E for the regex

sed is intended to do replacing.

Upvotes: 3

Related Questions