How can i replace a character with blank space? | Unix Linux Forums | AIX

  Go Back    


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

How can i replace a character with blank space?

AIX


Tags
aix, unix

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-14-2008
rollthecoin rollthecoin is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 14 June 2009, 10:39 AM EDT
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
How can i replace a character with blank space?

i want a command for my script!!!

say file consists of character 123 125 127.

i need a query to replace the number 2 with 0

so the output should be 103 105 107.

i use unix-aix
Sponsored Links
    #2  
Old 04-14-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 23 November 2014, 6:38 PM EST
Location: NM
Posts: 10,280
Thanks: 287
Thanked 814 Times in 756 Posts

Code:
tr -s '2'  '0' < oldfile > newfile

Sponsored Links
    #3  
Old 04-14-2008
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 24 November 2014, 1:40 AM EST
Location: In the leftmost byte of /dev/kmem
Posts: 4,337
Thanks: 45
Thanked 839 Times in 662 Posts
Quote:
Originally Posted by rollthecoin View Post
say file consists of character 123 125 127.
I am not sure about what you mean: ist this the text as it is in your file or are these decimal (octal?) values for three characters in your file?

If this is text you can use the following:


Code:
sed 's/12\([0-9]\)/10\1/g' /path/to/file > /path/to/other/file

I hope this helps.

bakunin
    #4  
Old 04-16-2008
rollthecoin rollthecoin is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 14 June 2009, 10:39 AM EDT
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
No.

I will tell you clearly.

i want to delete a invalid character(which i told you as example '2'.)

The query should check for characters which is not present in the following
A to Z,
a to z ,
0 to 9
and all the symbols present in the keyboard.

If you have any doubts reply me.

Last edited by rollthecoin; 04-16-2008 at 06:34 AM..
Sponsored Links
    #5  
Old 04-17-2008
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 24 November 2014, 1:40 AM EST
Location: In the leftmost byte of /dev/kmem
Posts: 4,337
Thanks: 45
Thanked 839 Times in 662 Posts
Quote:
Originally Posted by rollthecoin View Post
The query should check for characters which is not present in the following
A to Z,
a to z ,
0 to 9
You have already solved the problem almost - all on your own. Just construct a simple regular expression from your goal:


Code:
[^A-Za-z0-9.,#&@]

will find any characters which are not small characters, capitalized characters, digits or some punctuation characters. Add in the brackets more punctuation characters to exclude them too from the found characters as per your request. Now put this mechanism to work with "sed" or whatever:


Code:
sed '/[^A-Za-z0-9.,#&@]//g' /path/to/sourcefile > /path/to/newfile

will delete all the characters not covered in the regexp and write the result to a file. Check this file and modify the regexp as necessary depending on the result.

I hope this helps.

bakunin
Sponsored Links
    #6  
Old 04-18-2008
rollthecoin rollthecoin is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 14 June 2009, 10:39 AM EDT
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Myscript

#!/usr/bin/ksh
sed '/[^A-Za-z0-9.,#&@]//g' /home/1.txt > /home/2.txt


it throws error like this
"sed: 0602-403 /[^A-Za-z0-9.,#&@]//g is not a recognized function."


why is it so.
did i do any mistake?

Last edited by rollthecoin; 04-18-2008 at 04:40 AM..
Sponsored Links
    #7  
Old 04-18-2008
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 24 November 2014, 1:40 AM EST
Location: In the leftmost byte of /dev/kmem
Posts: 4,337
Thanks: 45
Thanked 839 Times in 662 Posts
My bad, i had a typo in the script:


Code:
sed '/[^A-Za-z0-9.,#&@]//g' /path/to/sourcefile > /path/to/newfile

should be


Code:
sed 's/[^A-Za-z0-9.,#&@]//g' /path/to/sourcefile > /path/to/newfile

bakunin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replace colon with blank space chumsky UNIX for Dummies Questions & Answers 2 11-24-2011 03:44 AM
Replace comma with a blank space using SED jayT Shell Programming and Scripting 5 01-21-2011 10:42 AM
how to replace a character with blank in a file sridhusha Shell Programming and Scripting 4 02-02-2010 09:08 AM
Replace a blank space with string "\\ " Akshay4u Shell Programming and Scripting 7 02-06-2009 05:10 PM
How to replace all entries of comma in text file by space or other character prashant43 Shell Programming and Scripting 4 08-30-2008 01:53 AM



All times are GMT -4. The time now is 02:42 AM.