LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Containers (https://www.linuxquestions.org/questions/linux-containers-122/)
-   -   Identify the special characters in file in unix (https://www.linuxquestions.org/questions/linux-containers-122/identify-the-special-characters-in-file-in-unix-4175627245/)

deep_kol 04-08-2018 05:02 AM

Identify the special characters in file in unix
 
Hi Friends ,
Need your help to solve this issue . Need to identify the special characters in a file . I tried the below way .

Step 1 :
Create data file test.txt

Quote:


105712848,161,20180115,20180331,552,abc
105712848,160,20180115,20180331,240,abc 2018
104231840,475,20180115,20180331,192,xyz 2018
104231840,475,20180115,20180331,192,xyz 2018@

Steps 2 : run the syntax
Quote:

grep -v "^[A-Za-z0-9,]*$" test.txt
it should give you the below record ,bcz it has a special character @
104231840,475,20180115,20180331,192,Salt 2018

But it does not . Can you please let me know what is wrong in this

pan64 04-08-2018 05:29 AM

probably you missed some chars, like space (from your regexp).

BW-userx 04-08-2018 02:49 PM

thats a tricky one,

Code:

$ egrep '[0-9A-z]@' findchars
104231840,475,20180115,20180331,192,xyz 2018@

might not be the exact what you're looking for though. could just look for the special char.
Code:

$ egrep '@' findchars
104231840,475,20180115,20180331,192,xyz 2018@

all the other are canceled out, no need to even look for them. just set it up to look for the special char(s) you're looking for.

deep_kol 04-08-2018 05:28 PM

This way i have to identify all the special characters and hard code them .It will not fulfill my requirement.
Quote:

$ egrep '@' findchars
104231840,475,20180115,20180331,192,xyz 2018@
Do not understand why the below syntax does not give the correct result .

Quote:

grep -v "^[A-Za-z0-9,]*$" test.txt

BW-userx 04-08-2018 05:44 PM

Quote:

Originally Posted by deep_kol (Post 5840856)
This way i have to identify all the special characters and hard code them .It will not fulfill my requirement.

Code:

grep -v "^[A-Za-z0-9,]*$" test.txt
Do not understand why the below syntax does not give the correct result .

did you notice you're identifying all of the other characters and not getting your desired results? that is all I know about that one. let research it?

pan64 04-09-2018 01:33 AM

Quote:

Originally Posted by deep_kol (Post 5840856)
Do not understand why the below syntax does not give the correct result .

Repeating the same question will not help. Would be nice to explain what should be the correct result, what did you get instead. Also did you check post #2?

BW-userx 04-23-2018 10:50 AM

I think your best bet is to work on the basics. First figure out what a pattern is, or what does a pattern consist of,
or what qualifications does something have to have in order to be defined as a pattern? Whence you figure that out,
then move onto the next step, finding a program that searches for patterns and learn how to use it to do just that.
If you have any difficulties arise then seek guidance for same.


All times are GMT -5. The time now is 11:35 PM.