remove special charaters from a .CSV file

I want a script to  remove all the special characters from a .CSV file.  Thanks in advance
Contents of the file is like follows:

WF_CRIT_INCL_CD,Übereinst. erf. (Schreibw. e.),EQ_THIS_NC,German,Common,7,N,Y,Y,
WF_CRIT_INCL_CD,Größer als,GREATER_THAN,German,Common,9,N,Y,Y,All,
WF_CRIT_INCL_CD,Kleiner als,LESS_THAN,German,Common,10,N,Y,Y,All,
WF_CRIT_INCL_CD,Nicht zwischen,NOT_BETWEEN,German,Common,12,N,Y,Y,All
WF_CRIT_INCL_CD,Gleich Null,IS_NULL,German,Common,13,N,Y,Y,All
WF_CRIT_INCL_CD,Ungleich Null,IS_NOT_NULL,German,Common,14,N,Y,Y,All
WF_CRIT_TYPE_CD,Business Component,BUSCOMP,German,Common,2,N,Y,Y,All
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

which characters are special?
conversekidAuthor Commented:
In this example there are not special characters. I just wanted to give the format. We need to find and remove all the special characters if any..
what are "special characters"?
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

conversekidAuthor Commented:
Hi ,

The following are special characters:

@"?/>.<,:;""'{[}]|\\+=_-)(*&^%$#@!~`";  Thanks
well then

cat file | sed 's/[@\?\/>.<,:;{[}]|\\+=_-)(*&^%$#@!~`";]//g'  > file.nospecialchar
with the correct escaping of course :-S

or maybe you could just use all non word characters, but as I've seen you also have non-ascii characters that are considered as valid
cat file | sed 's/\[[]!@#$%^&\*(){}",.><~`\]*//g' | sed "s/'*//g" > file.nospecialchar

would be a solution
Brian UtterbackPrinciple Software EngineerCommented:
You can do the same thing more efficiently with the tr command:

/usr/bin/tr -d '[:punct:]' < file > file.nospecialchar

This is assuming you are using the "C" locale. run the locale command to check, if you don't know.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
conversekidAuthor Commented:

Great!  Is it possible for me to have a small script so that I can change the characters to be removed from the file?
but I'd advice you to use blu's suggestion, though you can't modify what is a "punct"uation there, but it will respect your locale.

about the script below, be careful, there are some characters to be backslashed, other not...

you use the script below that way : source.csv destination.file
cat $1 | sed 's/\[[]!@#$%^&\*(){}",.><~`\]*//g' | sed "s/'*//g" > $2

Open in new window

Brian UtterbackPrinciple Software EngineerCommented:
Well, in the case of the tr with the character class '[:punct:]' the answer is no, because each locale defined has its own set of characters that are recognized as punctuation. However, you give the characters to the tr command in the same way
that zino did to the sed command. Just replace the [:punct:] part with the list of characters you want to delete.

It can get tricky depending on your shell and the characters you want to remove. Some of the letters will possibly need to be escaped. You may even need to use the octal escape version. See the tr man page.
conversekidAuthor Commented:
Hi, I definitely agree with blu's suggestion. I am trying to get it as a script so that I can give it to users.

zmo, if possible can you help me understand why we are using sed twice...and is it possible to take the input from the user as in what to remove and then remove the same....only if its easy to make it that way.
I did sed twice because of a weird reason I could'nt put the single quote character escaped in the first sed.

You can use the "read" command (man read) to get the characters, but be careful of what you take there, because some characters will need to be escaped others not...
conversekidAuthor Commented:
Thanks to Zmo and blu for your quick response..!!!!!!!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.