Computing.Net > Forums > Unix > find unwanted characters in file

find unwanted characters in file

Reply to Message Icon

Original Message
Name: Criamon
Date: July 30, 2005 at 05:28:07 Pacific
Subject: find unwanted characters in file
OS: SunOS 5.8
CPU/Ram: ?
Comment:

Hi there,

would be great if you can help me. I have to find unwanted characters in a file, and all I have is a positive list of allowed characters as regular expression [a-zA-Z0-9 \[\]{}#\,\.();]. Using awk makes no sense, as each line also contains one of the allowed chars and isn“t found thereby :(

Thanks in advance

Criamon


Report Offensive Message For Removal

Response Number 1
Name: Luke Chi
Date: July 30, 2005 at 09:28:57 Pacific
Subject: find unwanted characters in file
Reply: (edit)

I did the same job before.

I wrote a very simple C program using getc() to read the char one by one from the input file. If the char is in [a-zA-Z0-9 \[\]{}#\,\.();], then putc() to the output file, else do nothing.

It was a very simple C program.

Luke Chi


Report Offensive Follow Up For Removal

Response Number 2
Name: vicchai
Date: July 31, 2005 at 07:24:11 Pacific
Subject: find unwanted characters in file
Reply: (edit)

Try this following command, it work on Redhat 9:

awk '!/[[:almun:]\[\]{}#,.();]/' file.txt

It will list all lines not match the regular expression.


Report Offensive Follow Up For Removal

Response Number 3
Name: Luke Chi
Date: July 31, 2005 at 14:03:28 Pacific
Subject: find unwanted characters in file
Reply: (edit)

sed 's/[^a-zA-Z0-9 \[\]{}#\,\.();]//g' file.txt


Luke Chi


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: find unwanted characters in file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software