Grep all string which do not starts with number(s)
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/\<\d\w*\>//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
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
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 "'"'?/\n\n\n\n\n\n/;/^[_[:alpha:]]/P;D"
...the above should do fairly well. You'll want to tailor the \n
ewline 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.