To make it "work" you should use double quote instead of single quote, but your formula is NOT correct :
if you have
and you want then :
Y is at the 4th position, but if you run
you will get
because the sed statement will replace the 4th '-' instead of the 4th character.
I have updated my previous post about how to change the n th character, pls check it
---------- Post updated at 04:10 PM ---------- Previous update was at 04:04 PM ----------
... by the way, using "hash" as a filename is a bad idea since "hash" already is a standard unix command name.
This is what i have done
were hash is the file that contains the hash of the word '--------'
$input is the inputed character
$i is were the character should go (index of the character)
but i have one problem which is
if a word like 'kitten' comes up and i input 't' the output is
or internet and i input e
the second instance of the same character is always one place ahead
my code
$charCount is the character count and is always 1 more. e.g the word 'car' is 4 characters
$input is what the user inputs or it is the gussed character
hash is the file that contians the hash '-----'
randomWordFile is the file that contains the word
---------- Post updated at 03:25 PM ---------- Previous update was at 03:19 PM ----------
Basically
i need to take the $i character of the word and replace it with $input and not take the $i instance of the word and replace it with the character
Last edited by Franklin52; 02-28-2011 at 03:22 PM..
Reason: Please use code tags
to replace the n th character:
example to replace the 3rd character :
---------- Post updated at 04:54 PM ---------- Previous update was at 04:29 PM ----------
to replace the n th character:
example to replace the 3rd character :
Hi, ctsgnb:
You can simplify that quite a bit using a posix-standard substitution flag:
Regards,
Alister
---------- Post updated at 03:15 PM ---------- Previous update was at 03:12 PM ----------
Woops. I started reading this thread backwards and just now saw that you and others have already covered that. I apologize. In a short while I'll have breakfast before I get out of bed and then wake up.
Hi,
I am beginner to Shell Scripting.
I have a String like this "testabcdef", i need the first character as it is and the remaining character should be replaced by the the '*' character. e.g(t***********)
PLZ Suggest me. (5 Replies)
I have a string eg.
word=promise
and I have the masked version of the word which is -------(7dash for each character)
if the user input a character O, I want the masked version of the word to be --o----
if the user inputs another character p, then the masked word becomes p-o----
How can i... (1 Reply)
Hello everyone this is my first post of many to come :)
I am writing a script and in this script at one point i need to replace a character in a particular position in a string for example:
in the string "mystery" i would need to replace the 3rd position to an "r" so the string becomes... (3 Replies)
Hi,
Could someone help me how to replace last character string.
For example
$>export T1=abcde
$>export T2=xyz
my question is how to get result abcdxyz?
Many Thanks (2 Replies)
Hi,
i have string var1=NN. Based on conditions, i have to change this first N to Y or second N to Y and send the details to other process. How to do that? This is a linux machine.
Thanks,
Selva (1 Reply)
Need to replace any control character in the string in perl
---------- Post updated at 04:22 PM ---------- Previous update was at 03:50 PM ----------
Any help !!!
Thanks in advance (2 Replies)
Hi all,
My problem is the following:
I've a script that must list all files in a directory and write this information in a text file.
I've tried to get the list through ls command and then write it using msgecho
msgecho "`ls $PATH_APS_JOB_ORA`"
This works good but the created string... (7 Replies)
I am facing one problem, can any one please suggest me the command for the same in unix. I am using Ksh.
I have a large file with the data that looks like below.
"ROTO2-2007f","_US01","9/15/2007","9/21/2007",346492,"NICK, LCD WATCH"97,1,"NAPOLITJ ","BERGER,M Z & CO INC",0.01,
... (2 Replies)