I want to show only the numbers and characters, not other specific symbols. I tried this:

grep [0-9,A-Z] ika

but working it is not working now, it shows specific symbols also.

closed as unclear what you're asking by Jeff Schaller, RalfFriedl, Romeo Ninov, G-Man, mosvy Nov 17 at 16:50

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • the command you show will display lines with any of those characters in it; what's your desired output? Also, be sure to quote that pattern to protect it from the shell, in case you had a file named , or C in your current directory, you wouldn't get what you expect. – Jeff Schaller Nov 16 at 18:46
  • Do you mean numbers and letters? "Symbols" are characters. – jpmc26 Nov 16 at 22:56
up vote 2 down vote accepted

The following examples show how to get what you want:

These commands show the whole line containing the search string.

$ <<< 'asdf$@12' grep as
$ <<< 'asdf$@12' grep '[0-9A-Z]'

You can high-light the search string in the line

$ <<< 'asdf$@12' grep --color '[0-9A-Z]'

You can print only the search string (in this case one-character digits and upper case letters)

$ <<< 'asdf$@12' grep --color -o '[0-9A-Z]'

If you want all letters, you should search for lower case letters too

$ <<< 'asdf$@12' grep --color -o '[0-9A-Za-z]'
  • Thanks for single quotes, @JeffSchaller :-) – sudodus Nov 16 at 19:03
  • Do you want commas displayed in the result? If no, remove from the pattern resp. regex. – RudiC Nov 16 at 19:05
  • touch C for a quick reason why :) – Jeff Schaller Nov 16 at 19:06
  • Thanks for suggesting to remove the commas, @RudiC :-) – sudodus Nov 16 at 19:12

Try also

<<< 'asdf$@12' tr -cd 'a-zA-Z0-9'

or use a character class, like

tr -cd '[:alnum:]'

Not the answer you're looking for? Browse other questions tagged or ask your own question.