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

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

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:

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

I hope this helps.

bakunin

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.

You have already solved the problem almost - all on your own. Just construct a simple regular expression from your goal:

[^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:

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

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?

My bad, i had a typo in the script:

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

should be

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

bakunin

Hi,

I want to insert a single or two or three spaces at a particular position.
Hope u understood from the input and how the output should be?
How to determine the position after 234 or adf or whatever it can be?

Say the data is like

input
12345 2345 234 789
abcd defr adf red

output
12345 2345 234 789
abcd defr adf red

I want to insert space without referencing the 234 or adf or watever?