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?
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/\<\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
\> Matches the null string at the end of a word. This is equivalent to[[:>:]]'.`
– Matteo
Feb 26 '15 at 10:56
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 \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.
! ahead of the '"' swap, but if you're using bash you might want set +H or if zsh then set -K. In my opinion, any quoted ! expansion is insanity. You can also use heredocs like "${0#-}" <<\CMD\nyour cmd strings\nCMD\n to get scripted behavior in interactive shells.
– mikeserv
Feb 26 '15 at 18:23
"${0#-}" -s -- arg list <<\CMD\n... you can also set the positional parameters at invocation. Using "$@" or * is often useful for me in place of arg list. And with ln -s "$(command -v "${0#-}")" /tmp/new_name; cd tmp; new_name <<\CMD\n... you can get a new $0 and still handle stdin.
– mikeserv
Feb 26 '15 at 18:34
-vwith-ocausinggrepproduce no output. – cuonglm Feb 25 '15 at 16:43grepuses basic regular expressions. This means that your?is being treated as a literal question-mark. Either escape the question-mark\?, or use the-Eoption forextendedregular expressions, in which case?is a pattern character. – Peter.O Feb 25 '15 at 17:25