The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing certain characters in a file bombcan Shell Programming and Scripting 2 04-25-2008 12:53 PM
Replacing characters in csv file finwhiz UNIX for Dummies Questions & Answers 1 03-31-2008 02:25 AM
Invalid Characters in the file. kanu_pathak Shell Programming and Scripting 5 02-01-2008 05:45 AM
how to see special characters in a file using vi jingi1234 UNIX for Dummies Questions & Answers 6 10-19-2005 08:57 AM
grepping the first 3 characters from a file rachael UNIX for Dummies Questions & Answers 2 10-15-2001 11:33 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #8 (permalink)  
Old 02-01-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
Thanks Perderabo...

I am using AIX, version 4.

I want to keep the special characters like double quotes("), spaces, +, - etc. retained. When I used :
tr -c '[:print:][:cntrl:]' ' ' < input_file > output_file

all these characters also got removed. (Anything to do with [:print:] ?)


Also, [:alnum:] didn't change the file itself :

tr -c '[:alnum:]' ' ' < subs.bak > sub.err


Have got tired of using so many options. Have to resolve this issue as soon as possible. Clients jumping on me.

Thanks
Kanu
Reply With Quote
Forum Sponsor
  #9 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
Unhappy

Are there some more options? Thanks in advance..
-Kanu
Reply With Quote
  #10 (permalink)  
Old 02-04-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,573
If the list of characters to be removed is finite have them in the file "unwanted_chars"

and try this code

Code:
#! /opt/third-party/bin/perl

open(FILE, "<", "unwanted_chars");

while(<FILE>) {
  chomp;
  $fileHash{$_} = 0;
}

close(FILE);

open(FILE, "<", $ARGV[0]) || die ("unable to open <$!>\n");

while( read(FILE, $data, 1) == 1 ) {
  $ordVal = ord($data);
  print $data if( !defined($fileHash{$ordVal}) );
}

close(FILE);

exit 0
But if you are sure only ASCII characters need to be in the data file then its much more simpler, range can be specified and no need to use an external lookup file
Reply With Quote
  #11 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
Thanks Madhan! The list of characters is not finite. These are some dump character which creep into the records. I believe it would be helpful if you see my attached example.

Anyways, the logic is good. Atleast I can remove some of the characters which I know.

Thanks
Kanu
Reply With Quote
  #12 (permalink)  
Old 02-04-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,573
Quote:
These are some dump character which creep into the records.
I doubt that. Could you please double - check what is the encoding character that is set as default and what is the encoding character set of the input file ?

Actually these are valid characters but not for all the character sets.

It might be that they are valid and due to the encoding character set of the terminal it might turn out to be junk or unwanted characters.

Better take a hex dump of the file and verify its needed or not
Reply With Quote
  #13 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
I dont know why, but I always wanted to get this answer.
I always doubted this. I think at the place of 'space' some dump characters are coming.
How can I check the encoding character set of the terminal?
Can I change it too?
I want to resolve the root cause, so that we can avoid using some more scripts.

Thanks
Kanu
Reply With Quote
  #14 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jan 2008
Location: India
Posts: 34
Question

This is what I got :

#echo $LANG
En_US

Helpful?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:51 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0