All right, now I got it. Shame on me that I did not find out that myself. I was staring at that code and was wondering how can be that it filters out all the mentioned special chars
\s is not valid in posix-compliant posix (perhaps it's a gnu sed extension, but I'm not sure). Even if it's allowed, that regular expression would only match a line with one matching character. And, since sed prints all lines by default, the p command in this case will cause matching lines to print twice.
Two portable sed alternatives:
sed -n '/^[[:alnum:][:blank:].-]*$/p' file1
sed '/^[[:alnum:][:blank:].-]*$/!d' file1
The first disabled printing by default, with the -n option, and then only prints lines that consist of nothing but the allowed characters. The second option deletes all lines that do not consist of all matching characters.
Regards,
Alister
---------- Post updated at 11:56 AM ---------- Previous update was at 11:53 AM ----------
I've been having vision troubles the past few days. Seconds after posting, I noticed anbu's post. Mine is essentially the same, except it uses character classes.
Thanks a lot anbu23 and Alister, it was very helpful. I have a doubt. how can i do this task for a particular part of the line..for example, i want to check for the special characters in all lines from position 10 to 20 only..