Input String Manipulation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Input String Manipulation
# 1  
Old 07-24-2008
Input String Manipulation

I am writing a script that will accept input parameters and then turn on flags from the parameters read in. I know how to do this with reading in each parameter as a seperate variable (./program.ksh e p were $1=e $2=p), but would like to be able to combine all into one and then parse the values.

Ex call statement: ./program.ksh -ep

Within program.ksh
store var1=e
store var2=p

Total number of parameters for program.ksh 0..4
# 2  
Old 07-24-2008
Did you try getopts?

Code:
zsh-4.3.4% cat s
#! /bin/ksh

(( $# < 1 )) && { printf "Usage: $0 ...\n"; exit 1;}

while getopts ":epxz" opt; do
  case "$opt" in
     e ) print "e is set" ;;
     p ) print "p is set" ;;
     x ) print "x is set" ;;
     z ) print "z is set" ;;
    \? ) echo "Usage: $0 [OPTION] ... " ;
return 1 ;;
  esac
done

For example:

Code:
zsh-4.3.4% ./s
Usage: ./s ...
zsh-4.3.4% ./s -t
Usage: ./s [OPTION] ...
zsh-4.3.4% ./s -e
e is set
zsh-4.3.4% ./s -epxz
e is set
p is set
x is set
z is set
zsh-4.3.4% ./s -e -p -z
e is set
p is set
z is set

# 3  
Old 07-24-2008
Nope. That appears to be exactly what I was looking for. Thank you for the quick response.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

String manipulation

i have a string that am looking to extract all characters following 3 consecutiv numbers. Example my string is J1705PEAN038TDMN, i need to get TDMN My string can have multiple 3 consecutive numbers, i need what follows last occurance (9 Replies)
Discussion started by: gigagigosu
9 Replies

2. Shell Programming and Scripting

Deleting part of a string : string manipulation

i have something like this... echo "teCertificateId" | awk -F'Id' '{ print $1 }' | awk -F'te' '{ print $2 }' Certifica the awk should remove 'te' only if it is present at the start of the string.. anywhere else it should ignore it. expected output is Certificate (7 Replies)
Discussion started by: vivek d r
7 Replies

3. Shell Programming and Scripting

String manipulation

I want to do the next "I don't want to go school because I'm sick today." I want to join these two line but only when the first line is not more than 20 characters and ended whit nothing or a comma and the second line not more than 15. The 20 and the 15 can be change in the script. I know... (10 Replies)
Discussion started by: thailand
10 Replies

4. Shell Programming and Scripting

Help With String Manipulation

Hi Guru's, I need some help with data manipulation using shell scripting. I know how to replace the whole string but not part of the string. The value after aa= should be replaced with the value in the mail leaving ,OU=111,OU=222,DC=333 as is. Below are the inputs and expected outputs. Input:... (17 Replies)
Discussion started by: Samingla
17 Replies

5. Shell Programming and Scripting

string manipulation

if I have two string variable, how do I add one to anther. like a= "a" b="b" c=$a+$b but that doesn't work. Is there anyway to solve it.http://www.qtl.co.il/img/copy.pnghttp://www.google.com/favicon.icohttp://www.babylon.com/favicon.icohttp://www.morfix.com/favicon.ico (2 Replies)
Discussion started by: programAngel
2 Replies

6. Shell Programming and Scripting

String Manipulation

How u convert string "hi pravin how are you?" to "Hi Pravin How Are You?" (4 Replies)
Discussion started by: proactiveaditya
4 Replies

7. UNIX for Dummies Questions & Answers

String manipulation

I am doing some training for a job I have just got and there is an exercise I am stuck with. I am not posting to ask a question about logic, just a trivial help with string manipulation. I would appreciate if somebody could at least give me a hint on how to do it. Basically, the intelligent part... (8 Replies)
Discussion started by: Dantastik
8 Replies

8. Shell Programming and Scripting

String manipulation

Hi, i am just gettin exposed to UNIX. Could anyone of u help me out with dis problem..? i have a variable 'act' which has the value as follows, echo $act gives -0- -0- -----0---- 2008-06-04 -0- -0- echo "$act" | awk '{print ($act)}' gives, -0- -0- -----0---- 2008-06-04 -0- -0- I... (2 Replies)
Discussion started by: jerrynimrod
2 Replies

9. Shell Programming and Scripting

String Manipulation Help

Hey Guys, Right i know how to alter a word to begin with a capital letter, i know how to remove unwanted characters and replace them with the relevant character however i don't now if there is a way to do them all in one line. Code: echo -n ${string:0:1} | tr a-z A-Z #convert first letter... (4 Replies)
Discussion started by: shadow0001
4 Replies

10. Shell Programming and Scripting

String Manipulation

Hi, Suppose I have the following text in a file. ORA-00942: table or view does not exist ORA-01555: snapshot too old: rollback segment number string with name "string" too small Is there any way I can list all the text that starts only with 'ORA-'? Or there any grep command that can... (7 Replies)
Discussion started by: kakashi_jet
7 Replies
Login or Register to Ask a Question