Script argument manipulation ...

How am I going to take an argument and then modified it and become another new parameter for my script?

Example:  my_script  A123

In my script, I shall add let say "MS" in front of argv1 and join them together and insert a "." (dot) after the third character of the argv. The new parameter will become "MSA12.3". Then I shall proceed further to manipulate this parameter.

Thanks.
qiang8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
What language is your script written in?  Assuming sh:

set -- `awk 'END{print "MS"substr(x,0,3)"."substr(x,4)}' x=$1`
0
ahoffmannCommented:
except in ksh (not shure about bash, zsh), you cannot modify positional parameters, you need to copy them to internal variables, then see ozo's suggestion
0
qiang8Author Commented:
I have tried the following in csh but none can work .....

Example:  my_script A123
Contents are as follow:

1.
#!/bin/csh -f
awk 'END{print "MS"substr (x,0,3) "." substr(x,4)}' x=$1

2.
#!/bin/csh -f
awk '{print "MS"substr(x,0,3)} x=$1 '

3.
#!/bin/csh -f
awk 'END{print "MS"substr($1,0,3)"." substr($1,4)}'


Pls advise.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

ozoCommented:
set argv[1]=`awk 'END{print "MS"substr(x,0,3) "." substr(x,4)}' x=$1`
0
ahoffmannCommented:
set new = `echo $1 | awk '{print "MS"substr($0,0,3)"."substr($0,4)}'`
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bedotCommented:
here a very basic response using regular expressions, sed & expr, well-working in all environments unix



end=`expr $1 : '.*\(.\)$'`
mid=`echo $1 | (sed -e s/.$/./)`
result=MSA$mid$end
echo $result


typîng hello, will produce MSAhell.o

beware at quotes, antiquotes, slash ans antislash
0
ahoffmannCommented:
bedot, is *sh syntax, not *csh,
also the argument contains no dot as you assume in your expr
0
qiang8Author Commented:
Thanks a lot ...
0
bedotCommented:
AHOFF: i don't assume dots: in a regular expression a dot represent any character
0
ahoffmannCommented:
oops, should use lynx, or change my browser's font
sorry for incorrectly reading, bedot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.