I have a fixed width file with 10-15 columns. The file contains alphanumeric values. How do I check for any special characters (like !,@,#,$,% etc.) in the entire file in UNIX ?
Asked
Active
Viewed 4.4k times
1
-
there is a character class called punct .check for it. `[[:punct:]]`, may be it help. – P.... Oct 13 '16 at 12:40
1 Answers
1
try this;
grep -vn "^[a-zA-Z0-9]*$" yourFile
or
grep -vn "^[[:alnum:]]*$" yourFile
man grep :
-v, --invert-match Invert the sense of matching, to select non-matching lines.
-n, --line-number Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)
[[:alnum:]] means the character class of numbers and letters in the current locale

Mustafa DOGRU
- 3,994
- 1
- 16
- 24
-
1You might want to allow whitespace as valid characters: `grep '[^[:alnum:][:blank:]]'` – glenn jackman Oct 13 '16 at 16:12