Show only number and characters not Specific symbols [closed]
up vote
2
down vote
favorite
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.
linux grep
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.
add a comment |
up vote
2
down vote
favorite
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.
linux grep
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,
orC
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
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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.
linux grep
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.
linux grep
linux grep
edited Nov 16 at 18:55
Isaac
9,69211445
9,69211445
asked Nov 16 at 18:30
Irakli
183
183
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.
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,
orC
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
add a comment |
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,
orC
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
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
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
Do you mean numbers and letters? "Symbols" are characters.
– jpmc26
Nov 16 at 22:56
add a comment |
2 Answers
2
active
oldest
votes
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
$ <<< 'asdf$@12' grep '[0-9A-Z]'
asdf$@12
You can high-light the search string in the line
$ <<< 'asdf$@12' grep --color '[0-9A-Z]'
asdf$@12
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]'
1
2
If you want all letters, you should search for lower case letters too
$ <<< 'asdf$@12' grep --color -o '[0-9A-Za-z]'
a
s
d
f
1
2
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
add a comment |
up vote
4
down vote
Try also
<<< 'asdf$@12' tr -cd 'a-zA-Z0-9'
asdf12
or use a character class, like
tr -cd '[:alnum:]'
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
$ <<< 'asdf$@12' grep '[0-9A-Z]'
asdf$@12
You can high-light the search string in the line
$ <<< 'asdf$@12' grep --color '[0-9A-Z]'
asdf$@12
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]'
1
2
If you want all letters, you should search for lower case letters too
$ <<< 'asdf$@12' grep --color -o '[0-9A-Za-z]'
a
s
d
f
1
2
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
add a comment |
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
$ <<< 'asdf$@12' grep '[0-9A-Z]'
asdf$@12
You can high-light the search string in the line
$ <<< 'asdf$@12' grep --color '[0-9A-Z]'
asdf$@12
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]'
1
2
If you want all letters, you should search for lower case letters too
$ <<< 'asdf$@12' grep --color -o '[0-9A-Za-z]'
a
s
d
f
1
2
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
add a comment |
up vote
2
down vote
accepted
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
$ <<< 'asdf$@12' grep '[0-9A-Z]'
asdf$@12
You can high-light the search string in the line
$ <<< 'asdf$@12' grep --color '[0-9A-Z]'
asdf$@12
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]'
1
2
If you want all letters, you should search for lower case letters too
$ <<< 'asdf$@12' grep --color -o '[0-9A-Za-z]'
a
s
d
f
1
2
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
$ <<< 'asdf$@12' grep '[0-9A-Z]'
asdf$@12
You can high-light the search string in the line
$ <<< 'asdf$@12' grep --color '[0-9A-Z]'
asdf$@12
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]'
1
2
If you want all letters, you should search for lower case letters too
$ <<< 'asdf$@12' grep --color -o '[0-9A-Za-z]'
a
s
d
f
1
2
edited Nov 16 at 19:11
answered Nov 16 at 18:57
sudodus
54615
54615
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
add a comment |
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
Thanks for single quotes, @JeffSchaller :-)
– sudodus
Nov 16 at 19:03
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
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
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
Thanks for suggesting to remove the commas, @RudiC :-)
– sudodus
Nov 16 at 19:12
add a comment |
up vote
4
down vote
Try also
<<< 'asdf$@12' tr -cd 'a-zA-Z0-9'
asdf12
or use a character class, like
tr -cd '[:alnum:]'
add a comment |
up vote
4
down vote
Try also
<<< 'asdf$@12' tr -cd 'a-zA-Z0-9'
asdf12
or use a character class, like
tr -cd '[:alnum:]'
add a comment |
up vote
4
down vote
up vote
4
down vote
Try also
<<< 'asdf$@12' tr -cd 'a-zA-Z0-9'
asdf12
or use a character class, like
tr -cd '[:alnum:]'
Try also
<<< 'asdf$@12' tr -cd 'a-zA-Z0-9'
asdf12
or use a character class, like
tr -cd '[:alnum:]'
edited Nov 16 at 19:24
answered Nov 16 at 19:03
RudiC
3,1311211
3,1311211
add a comment |
add a comment |
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
,
orC
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