How to delete characters using a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete characters using a file
# 1  
Old 09-22-2009
How to delete characters using a file

Hi All,
I have a configuration file (file.cfg) in which data will be like this
;
,
_
+
a to z
A to Z
Now i have to read a textfile (file.txt) and i need to check whether there is any other character present in text file that is not existing in (file.cfg).
If other characters are present in text file then those characters should be deleted.

Kindly help me.
# 2  
Old 09-22-2009
please send us the sample of two files

regards,
Sanjay
# 3  
Old 09-22-2009
Hi ,

configuration file will contain data like this:
;
,
.
_
a
b
c to z
A
B
C to Z

Text file will contain like this:

hello;*hello;[hello;
hello1;{hello1};hello1*

Now in text file there are some characters which are not there in configuration file (*,{,},[). These should be deleted
# 4  
Old 09-29-2009
what about c to z and c to Z and a,b,A and B.
Please make it very clear.or only you want to delete the special character which are not in config file.

regards,
Sanjay

---------- Post updated at 05:21 PM ---------- Previous update was at 05:17 PM ----------

if it is only regarding the special character then you can use tr command:

Code:
tr -d ';,._' < textfile

regards,
Sanjay
# 5  
Old 09-29-2009
Code:
open CFG, "<file.cfg" or die "Unable to open file.cfg";

$hash{10} = 1;

while(<CFG>)  {
    chomp;
    if (length($_) != 1 )  {
        ($a, $b) = /^(.).*(.)$/;
        $hash{ord $_} = 1 for ($a .. $b);
    } else  {
        $hash{ord $_} = 1;
    }
}

while(<>)  {
    foreach (split //, $_)  {
        print if ( $hash{ord $_} );
    }
}


Input:
Code:
hello;*hello;[hello;hello1;{hello1};hello1*

Output:
Code:
hello;hello;hello;hello;hello;hello

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need help to delete special characters exists only at the end of the each record in UNIX file?

Hi, I have a file in unix with 15 columns.It consists special characters(#,$,^M,@,*,% etc)at the end of the each record.I want to remove these special characters.I used the following: Sed -e 's/ /g;s/ */ /g' . But It is removing special characters exists everywhere in the file(begining,middle... (24 Replies)
Discussion started by: rakeshp
24 Replies

2. Shell Programming and Scripting

need to Delete first 10 characters of a file name

Hello Everyone, I need help in deleting first 10 characters from the filename in a directory eg: 1234567890samplefile1.txt 1234567890samplefile2.txt and so on.. need to get the output as samplefile1.txt Thanks in Advance!!!! (8 Replies)
Discussion started by: Olivia
8 Replies

3. Shell Programming and Scripting

how to delete special characters from the file content

Hello Team, Any one suggest how to delte the below special character from a file which is having one column 10 rows of same below content. ---------------------------------------- Kosten|bersicht gemd_ ' =Welche Kosten kvnnen... (2 Replies)
Discussion started by: kanakaraju
2 Replies

4. UNIX for Dummies Questions & Answers

Vim help - delete words in a file or characters after pattern

I have a file with words that begin with character #. Whenver that character is found that word should be deleted throughout the file. How do I do that in VIM. e.g: afkajfa ladfa ljafa #222222 kjafad ljl afajkj kjlj uouu #44444 jlkj lkjl Output should be afkajfa ladfa ljafa kjafad... (1 Reply)
Discussion started by: osbourneric
1 Replies

5. Shell Programming and Scripting

Delete new line characters from a file

Hi, I have a file with about 25 colums separated with '~', but few of the lines have extra tabs ('^') and new line characters ('$'). Is there a way I can delete those characters if they are anywhere before the 25th column in a line? example: CLUB000650;12345678;0087788667;NOOP MEMBER ... (4 Replies)
Discussion started by: rudoraj
4 Replies

6. Shell Programming and Scripting

Delete not readable characters

Hi All, I wanted to delete all the unwanted characters in the string. ie, to delete all the characters which are not alpha numeric values. var1="a./bc" var2='abc/\."123' like to get the output as print var1 abc print var2 abc123 Could you guys help me out pls. Your help is... (3 Replies)
Discussion started by: ajilesh
3 Replies

7. UNIX for Dummies Questions & Answers

how to delete M-^M characters from a file

I am receiving a file with 'M-^M' characters...how do I get rid of these characters. I tried tr -d '\015' and sed '/^M//g', but they didnot work. Appreciate if someone can help me with this (1 Reply)
Discussion started by: hyennah
1 Replies

8. UNIX for Dummies Questions & Answers

delete non printable characters from file

i have a file which contains non printable characters like enter,escape etc i want to delete them from the file (2 Replies)
Discussion started by: alokjyotibal
2 Replies

9. UNIX for Dummies Questions & Answers

How to delete a file with special characters

I don't now exactly how I did it, but I created a file named " -C " cexdi:/home1 $ls -lt total 1801336 -rw------- 1 cexdi ced-group 922275840 23 mars 10:03 -C How do I delete this file ? cexdi:/home1 $rm -C rm: invalid option -- C Syntax : rm filename ... Doesn't work...... (5 Replies)
Discussion started by: yveslagace
5 Replies

10. Programming

how to insert and delete characters in the middle of file

I have a problem that I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end. Is there any simple method or existing library that allow these actions? Thanks in advance.:confused: (7 Replies)
Discussion started by: ivancheung
7 Replies
Login or Register to Ask a Question