Troubling with delimiter. Please help. Im new to unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Troubling with delimiter. Please help. Im new to unix
# 1  
Old 07-28-2010
Troubling with delimiter. Please help. Im new to unix

Hi all, I have a problem in shell script. I think my script is a Konshell.
It has #!/usr/bin/ksh at the starting


I have a string variable which will store the value like this (This string is passed as an input parameter to script file from a java class)

Code:
paramList="-i 11 -x wcars412:8.0 -p empty -m wcars2kb -b null -s 47.134.26.243 -r 154 -n SOME_NAME -l NO -f AQIC5wM -v 10.10 -u admin -w pass"

(compare above string value to "key1 value1 key2 value2 key3 value3....)

In the above string -i, -x, -p, -m, -b, -s, -r, -n, -l, -f, -v, -u and -w are the keys and the values next to these keys are the values of those kesy

ex: -i(key1) 11 (value1), -x(key2) wcars412:8.0(value2)

I am using space as delimiter and breaking the string to get the values

But in the above string -n key will have some name as value (in place of SOME_NAME)

the problem is here is the SOME_NAME can have any number of special character and any number or spaces or any combination of numeric, alphabets and any special characters.

when I am breaking it with space or "-" as delimiter the name is also breaking up if the name contains the delimiter. My code is like this

Code:
while [ $index -le $totalNumber ];  ##$totalNumber is the number of args
    do
        param_key=`echo $paramList|cut -d ' ' -f$index`
         let index=index+1
           param_value=`echo $paramList|cut -d ' ' -f$index`
           let index=index+1
        case $param_key in
            "-i")
                NEID=$param_value                    
                continue;;
            "-x")
                DISPLAY=$param_value                   
                export DISPLAY
                continue;;               
            "-p")
                 PRESIDE_IP=$param_value
                continue;;
            "-m")
                  MASTER_CONTROLLER=$param_value
                continue;;
            "-b")
                  SLAVE_CONTROLLER_IP=$param_value
                continue;;
            "-s")
                  NE_IP=$param_value
                continue;;
            "-r")
                  NE_ROLE=$param_value
                continue;; 
            "-n")
                NE_NAME=$param_value
                continue;;
            "-application")
                APP_KEY=$param_value
                continue;;
            "-v")
                  NE_VERSION=$param_value
                continue;; 
            "-f")
                SSOKey=$param_value
                continue;;

            "-l")
                   isRtLWDLaunch=$param_value
                continue;;              
        "-u")
                UNAME=$param_value
                continue;;
        "-w")
                PASSWORD=$param_value
                continue;;
               *)
                echo "Invalid Parameter(s)."                    
         esac
     done
else
    echo "Invalid Parameter(s)."
    exit 1
fi

My idea is like this: I will pass the length of the SOME_NAME in the java class itself and append it at the end of the string like this "-q LENGTH"

Now In the above code I will get the index of the "-n" (say 35) and I will add the LENGTH(say 15) to the index. So now I wan to cut the 15 characters after the index of -n and store that in a variable.

Please help me with the code

Moderator's Comments:
Mod Comment Please use code tags to format code and listings, and be careful with colors

Last edited by pludi; 07-28-2010 at 10:28 AM..
# 2  
Old 07-28-2010
I am confused. You say it is a Korn shell script but then you start talking about Java classes.

If it is a shell script, you should use getopt to parse the command line options and the easiest way to handle spaces in the -n argument is to require that the argument be quoted i.e.
Code:
-n "This is some name"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join the line on delimiter using sed/awk in UNIX

I've input as , abcd| ef 123456| 78| 90 Desired output as, abcdef 1234567890 Anyone please give the solution. (5 Replies)
Discussion started by: jinixvimal
5 Replies

2. Shell Programming and Scripting

Perl Code to change file delimiter (passed as argument) to bar delimiter

Hi, Extremely new to Perl scripting, but need a quick fix without using TEXT::CSV I need to read in a file, pass any delimiter as an argument, and convert it to bar delimited on the output. In addition, enclose fields within double quotes in case of any embedded delimiters. Any help would... (2 Replies)
Discussion started by: JPB1977
2 Replies

3. Shell Programming and Scripting

Shell script to put delimiter for a no delimiter variable length text file

Hi, I have a No Delimiter variable length text file with following schema - Column Name Data length Firstname 5 Lastname 5 age 3 phoneno1 10 phoneno2 10 phoneno3 10 sample data - ... (16 Replies)
Discussion started by: Gaurav Martha
16 Replies

4. Shell Programming and Scripting

Scripting to fix the issue in UNIX file having delimiter "|"

hello All, I am new user to shell scripting, kindly advise on the below? I have a file where i have gaps & the delimiter falls in next line and new line is also created , plz see the example :employee.txt Now the issue here is , i wan to write a script , where i can use "|" to get the... (6 Replies)
Discussion started by: sunnyd1
6 Replies

5. Shell Programming and Scripting

How to cut by delimiter, and delimiter can be anything except numbers?

Hi all, I have a number of strings like below: //mnt/autocor/43°13'(33")W/ and i'm trying to get the numbers in this string, for example 431333 please help thanks ahead (14 Replies)
Discussion started by: sunnydanniel
14 Replies

6. Shell Programming and Scripting

how to find the nth field value in delimiter file in unix using awk

Hi All, I wanted to find 200th field value in delimiter file using awk.? awk '{print $200}' inputfile I am getting error message :- awk: The field 200 must be in the range 0 to 199. The source line number is 1. The error context is {print >>> $200 <<< } using... (4 Replies)
Discussion started by: Jairaj
4 Replies

7. Shell Programming and Scripting

Substring based on delimiter, finding last delimiter

Hi, I have a string like ABC.123.XYZ-A1-B2-P1-C4. I want to delimit the string based on "-" and then get result as only two strings. One with string till last hyphen and other with value after last hyphen... For this case, it would be something like first string as "ABC.123.XYZ-A1-B2-P1" and... (6 Replies)
Discussion started by: gupt_ash
6 Replies

8. UNIX for Dummies Questions & Answers

Delimiter

I am having the following file. I need to insert a delimiter in this file. I used sed but its not working. AAABBB 9 JJJ AAABBC 9 TTTTT AAABBA 8 JJJ AAABBC 7 TTTTT AAABBC 6 TTTTT Now i want the output file as: AAA|BBB| |9| |JJJ| AAA|BBC| |9| | |TTTTT| (3 Replies)
Discussion started by: sivakumar.rj
3 Replies

9. UNIX for Dummies Questions & Answers

Encoding Problem while using "|" (PIPE) as delimiter from Mainframe to Unix

We are facing a problem with PIPE (|) as a delimiter in one of our FTP flat files. We are constructing a Flat file in IBM-AIX and this contains various strings delimted by PIPE Symbol and then FTPing this to a Mainframe System The Mainframe program simply recieves this and FTPs the same... (1 Reply)
Discussion started by: seshendra
1 Replies

10. Shell Programming and Scripting

replace delimiter : with '\001' in unix data file

HI can any one tell me how to replace a delimiter : with another delimiter '\001' it is a non printable octal character. thanks in adv spandu (4 Replies)
Discussion started by: spandu
4 Replies
Login or Register to Ask a Question