Validate and sort input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Validate and sort input
# 1  
Old 08-25-2009
Validate and sort input

Hi,

This will most likely be a simple answer.

Currently I have a situation where my script will be sent various options:

Code:
-o1 -o2 -oe3@somthing.com

Now, if I want to run a certain command based on the option I am sent, I am doing the following.

Code:
for o in $(echo $options)
do
  if [ $o == "1" ]
  then
  
run commands
        exit 0
  fi
  if [ $o == "2" ]
  then
          run commands
        exit 0
  fi
done

However you will notice from my first example I gave "-oe3@something.com"

I need to be able to find where "-eXXX" is and then remove the 'e' and use the bit after (3@something.com). Or if it is easier, just forget about the "e" and look for anything with "@" init, but I would perfer to do the "e" method.

This next bit is later on at somepoint.

I will then want to "validate" what I have to check that is it a valid email address (You know so that it has an @ sign a domain name etc.
# 2  
Old 08-25-2009
You might go with getopts to process your options:

Code:
your_script -a -b -c -e email@address -f


Code:
OPTIND=1

while getopts abce:f
do
  case $ARGS in
    a) do something for option a
    ;;
    b) do something for option b
    ;;
    c) do something for option c
    ;;
    e) this_option=$OPTARG
        do something for option e based on the option
    ;;
    f) do something for option f
    ;;
  esac
done

# 3  
Old 08-25-2009
Quote:
Originally Posted by peterro
You might go with getopts to process your options:

Code:
your_script -a -b -c -e email@address -f

Code:
OPTIND=1

while getopts abce:f
do
  case $ARGS in
    a) do something for option a
    ;;
    b) do something for option b
    ;;
    c) do something for option c
    ;;
    e) this_option=$OPTARG
        do something for option e based on the option
    ;;
    f) do something for option f
    ;;
  esac
done

Thank you for your reply, unforuntaly in my particular situation I can't use getopts
# 4  
Old 08-25-2009
I guess then just capture the positional parameters ($1, $2 etc) and process them via the necessary commands such as awk or cut.

Code:
email=`echo $3 | awk -F-oe '{print $2}'`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validate input files daily

We have a job which we need to run on daily bases, before loading data in a table we need to validate whether the input file is received or not. Daily client will place the files in a particular path.Below files which I need to process for 04/01/2013(Load date).... (2 Replies)
Discussion started by: katakamvivek
2 Replies

2. Shell Programming and Scripting

Validate input files and update

We have a job which we need to run on daily bases, before loading data in a table we need to validate whether the input file is received or not.Inputfile formatsrc_sps_d_Call_Center_Reporting_yyyymmdd_01.dat SPS-Service nameYYYY-yearMM-MonthDD-dayLike above we will get n number of files for... (1 Reply)
Discussion started by: katakamvivek
1 Replies

3. Shell Programming and Scripting

How to validate user's input..?

$Input_filename=$ARGV; if (!-d $Input_filename && ! -e $Input_filename) { print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n"; exit; } 1. Input Is suppose to be something like "$ABCD/def/dsed.txt". if the input is wrong the script should throw an ERROR message.... (2 Replies)
Discussion started by: Rashid Khan
2 Replies

4. Shell Programming and Scripting

Epic - Validate input size

Is there an easy way to validate an input field size. Let us say a script is asking to enter 10 digits mobile number, how do I write a script to validate it is numeric and is 10 digits in length? I just need an easy way w/o using looks ...etc. Is there such a away ? Here is what I have so far... (6 Replies)
Discussion started by: mrn6430
6 Replies

5. Shell Programming and Scripting

Another validate input Question.

I'm writing a bash shell script to 'help' me post to susepaste (I can NEVER remember the time options). Here's the code: #!/bin/bash ########## # # Project : personal script. # Started : Wed Aug 03, 2011 # Author : Habitual # Description : susepaste c-li script with user... (5 Replies)
Discussion started by: Habitual
5 Replies

6. Shell Programming and Scripting

How to validate input parameters?

Hi, I wonder how I can know if the input parameters to the script are numbers or text Thanks (11 Replies)
Discussion started by: Gengis-Kahn
11 Replies

7. UNIX for Dummies Questions & Answers

BASH validate user input

Hey, im trying to validate a user input and need some help. The input needs to be just a single letter. Im using a case to so this eg: read answer case $answer in *) echo "OK" ;; *) echo "This is a number" read answer ;; *) echo... (2 Replies)
Discussion started by: 602chrislys
2 Replies

8. Shell Programming and Scripting

validate input

the user inputs names that have to be inside square brackets I want to check if the user puts the brackets and if not ask him to re-enter the names (9 Replies)
Discussion started by: DDoS
9 Replies

9. Shell Programming and Scripting

Need to validate a date input format

Hi all, I have a shell script(K shell) which takes a date as input. i want the input to be in DD-MM-YYYY format. Can i enforce such a format of input string using just one line of code? OR do i need to parse the input date into different components and test them using Case statements... (2 Replies)
Discussion started by: rajugp1
2 Replies

10. Shell Programming and Scripting

How to validate input values

Hi How would i validate value of a variable whether it is number,date or string Thanks in advance Sas (5 Replies)
Discussion started by: SasDutta
5 Replies
Login or Register to Ask a Question