Grep all string which do not starts with number(s)

I’m looking for grep to show all characters which do not starts with numbers.
I have done something like this:

grep -v '^[1-2]*[a-zA-Z]?' -o

but it do not work.
Do you have any idea for some reg exp?

grep -v '^[0-9]'

Will output all the lines that do not (-v) match lines beginning ^ with a number [0-9]

For example

$ cat test
string
string123
123string
1string2
$ grep -v '^[0-9]' test
string
string123

or if you want to remove all the words that begin with a digit

sed 's/[[:<:]][[:digit:]][[:alnum:]_]*[[:>:]]//g'

or with shortcuts and assertions

sed 's/<dw*>//g'

For example

$ cat test
one
two2
3three
4four4
five six
seven 8eight
9nine ten
11eleven 12twelve
a b c d
$ sed 's/[[:<:]][[:digit:]][[:alnum:]_]*[[:>:]]//g' test
one
two2


five six
seven 
 ten

a b c d
Answered By: Matteo

It depends how do you define a string (e.g. if you count punctuation characters to string or not). Nevertheless you may start from something like

grep -Po 'b[^[:digit:]].*?b' file
Answered By: jimmij

To remove all words from a line that begin with a number with sed you can do:

sed 'x;s/.*//;G
     s/[[:space:]][[:punct:]]{0,1}[0-9][^[:space:]]*//g
     s/n//'

…or, if you wanted only words which do not begin with numbers printed each on a separate line:

sed 'y/!t "'"'?/nnnnnn/;/^[_[:alpha:]]/P;D"

…the above should do fairly well. You’ll want to tailor the newline y///translation for dividers you think are relevant. And, sed implementation depending, you might also want an actual <tab> in place of the t backslash escape.

Answered By: mikeserv
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.