remove the special characters and move the file into another server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove the special characters and move the file into another server
# 1  
Old 02-21-2011
remove the special characters and move the file into another server

Quote:
Hi,
I have a file which contains comma delimiter data.
1)
Sample_data.txt

"Emp_ID","Filename","Ename","desc","code"
"2222","sample_data.txt","abc","BBBB","7776"
"2222","sample_data.txt","Kbc","KKKK","7774"

Based on the last column i am going to generate the new file with the following convention. Once the file is generated i am moving to another directory.

Emp_Information_$Ename_$desc_$code.csv
Output filename is
Emp_Information_Kbc_KKKK_7774.csv

But I am having some problem with the data. As I am getting the data in the below format

"Emp_ID","Filename","Ename","desc","code"
"2222","sample_data.txt","abc","BBBB","7776"
"2222","sample_data.txt","dbc","EE&EE","7779"

Emp_Information_dbc_EE&EE_7779.csv

I am able to generate a file but i am unable to move the file from one directory to another directory because As it is having & charter in the file name so it will treated as a UNIX command. I want to move this file to another server.
Quote:
2. I want to identify in the column how many special charters are present. I want to remove all the special charters [*,&,{,},(,),^,*] in the columns.

Example:
“Desc”
"B_BB&B"
"A&AA*A"
"C,CC^C"
"K)KK$K$^"

OUTPUT
"BBBB"
"AAAA"
"CCCC"
"KKKK"

Any help greatly appreciated.
Thanks suresh
# 2  
Old 02-21-2011
hi

you can use sed command for removing such type of characters

Code:
cat filename | sed "/Desc/d;s/_//g;s/&//g;s/*//g;s/\,//g;s/\^//g;s/)//g;s/\\$//g;s/(//g;s/{//g;s/}//g"

# 3  
Old 02-21-2011
Thanks for swift response. This is working fine.

I am not sure how many special charters are there in a file. I have mentioned only few special charters in the file. But I may get more special charters which we don't know. Overall, I want to remove any special charter other then charters and display. Any help greatly appreciated.
Thanks-Suresh
# 4  
Old 02-21-2011
I believe you can use the filename enclosed with a filename as "<filename>" when moving the file to another directory.
# 5  
Old 02-21-2011
Quote:
Thanks for the response.

I have many files generated at the same time. If I move files based on the file pattern then there is a problem. The best thing is remove the special charters and move the file into another directory.

Based on the above command I can remove the special charters but the problem as I don't know how many special charters I will get in the file. Any special charters simply remove and move the file to directory.
# 6  
Old 02-21-2011
ok fine.

I suggest before generating the filename ,correct the desc column (that is by removing the special characters)

by
Code:
sed -e 's/[^a-zA-Z0-9]*//g' <filename>


then generate the filename

Last edited by Franklin52; 02-21-2011 at 03:32 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

To remove any invisible and special characters from the file(exclude @#!$*)

Hi Guys, My requirement is to remove any invisible and special characters from the file like control M(carriage return) and alt numerics and it should not replace @#!$% abc|xyz|acd¥£ó adc|123| 12áí Please help on this. Thanks Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies

2. UNIX for Beginners Questions & Answers

To remove any invisible and special characters from the file(exclude @!#$&*)

Hi Guys, My requirement is to remove any invisible and special characters from the file like control M(carriage return) and alt numerics and it should not replace @#!$% abc|xyz|acd¥£ó adc|123| 12áí Please help on this. Thanks Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies

3. Shell Programming and Scripting

How to remove alphabets/special characters/space in the 5th field of a tab delimited file?

Thank you for 4 looking this post. We have a tab delimited file where we are facing problem in a lot of funny character. I have tried using awk but failed that is not working. In the 5th field ID which is supposed to be a integer only of that file, we are getting corrupted data as below. I... (12 Replies)
Discussion started by: Srithar
12 Replies

4. Shell Programming and Scripting

How to remove special characters?

Hi Gurus, I have file which contains some unicode charachator like "ü". I want to replace it with some charactors. I searched in internet and got command sed "s/ü/-/g", but I don't know how to type ü in unix command line. Please help me for this one. Thanks in advance (7 Replies)
Discussion started by: ken6503
7 Replies

5. UNIX for Advanced & Expert Users

What my puzzle file!, How to remove special characters ??

My application generate file but it have special characters in these file. I would like to clear special characters by vi editor and not use cat /dev/null > to_file I try to remove characters manually, but I'm can not! root@MyHost /tmp> ls -l puzzle.txt -rw-r--r-- 1 root system ... (5 Replies)
Discussion started by: arm_naja
5 Replies

6. Shell Programming and Scripting

Read file and remove special characters or strings

Hello all I am getting data like col1 | col2 | col3 asdafa | asdfasfa | asf*&^sgê 345./ |sdfasd23425^%^&^ | sdfsa23 êsfsfd | sf(* | sdfsasf My requirement is like I have to to read the file and remove all special characters and hex characters ranging form 00-1f from 1st column, remove %"'... (1 Reply)
Discussion started by: vasuarjula
1 Replies

7. Solaris

How to remove a directory or file with special characters in Solaris

I finally figured out how to remove a file or directory with special characters in the name. It's kind of rudimentary so I thought I would share it with everyone: find .inum -exec rm -rf {} \; (7 Replies)
Discussion started by: jastanle84
7 Replies

8. Shell Programming and Scripting

remove special characters

hello all I am writing a perl code and i wish to remove the special characters for text. I wish to remove all extended ascii characters. If the list of special characters is huge, how can i do this using substitute command s/specialcharacters/null/g I really want to code like... (3 Replies)
Discussion started by: vasuarjula
3 Replies

9. Shell Programming and Scripting

Remove special characters from text file

Hi All, i am trying to remove all special charecters().,/\~!@#%^$*&^_- and others from a tab delimited file. I am using the following code. while read LINE do echo $LINE | tr -d '=;:`"<>,./?!@#$%^&(){}'|tr -d "-"|tr -d "'" | tr -d "_" done < trial.txt > output.txt Problem ... (10 Replies)
Discussion started by: kkb
10 Replies

10. UNIX for Dummies Questions & Answers

How to Remove Special Characters

Dear Members, We have a file which contains some special characters. I need to replace these special character by a new line character(\n). The Special character is \x85. I am not sure what this character means and how we can remove it. Any inputs are greatly appreciated. Thanks... (5 Replies)
Discussion started by: sandeep_1105
5 Replies
Login or Register to Ask a Question