How to spilt huge string in AIX ?

I have few AIX 5.3 boxes where following is the issue.

I have a variable whose value is a very huge string ...(5000+ characters)

CMD_ARGS="/global/site/vendor/WAS/WebSphere6/AppServer/java/bin/java -Dcom.ibm.ws.client.installedConnectors=/global/site/vendor/WAS/WebSphere6/AppServer/profiles/dmgr/installedConnectors -Dcom.ibm.CORBA.ConfigURL......................................................................................:/global/site/vendor/WAS/WebSphere6/AppServer/lib/j2ee.jar com.ncode.DMIServer.DMIMain"

Now i want to capture everything except $1 i.e in above example... "-Dcom" onwards everything....

How do i do this ?

Regards
Abhi

It means,you want only the following from CMD_ARGS variable.

/global/site/vendor/WAS/WebSphere6/AppServer/java/bin/java
If so,you try the following command.

CMD_ARGS="/global/site/vendor/WAS/WebSphere6/AppServer/java/bin/java -Dcom.ibm.ws.client.installedConnectors=/global/site/vendor/WAS/WebSphere6/AppServer/profiles/dmgr/installedConnectors -Dcom.ibm.CORBA.ConfigURL......................................................................................:/global/site/vendor/WAS/WebSphere6/AppServer/lib/j2ee.jar com.ncode.DMIServer.DMIMain"
echo $CMD_ARGS | cut -d ' ' -f 1 #It will print the $1 as I explained above

probably i miswrote...

i do not want $1.... i want rest of it...

-Dcom.... onwards everything....

Regards
Abhi

Based on the previous suggestion, you could try:

echo $CMD_ARGS | cut -d ' ' -f 2- 

you could also use read

echo $CMD_ARGS | read FOO WHATYOUWANT
echo $WHATYOUWANT

-Dcom.ibm.ws.client.installedConnectors=/global/site/vendor/WAS/WebSphere6/AppServer/profiles/dmgr/installedConnectors -Dcom.ibm.CORBA.ConfigUR

funksen is correct. Per default the shell uses whitespace as field separator. I learned scripting on an IBM mainframe using REXX so i still follow the (there customary) convention of naming throw-away variables "." which works in ksh too. Like this:

typeset content=""
echo "word1 word2 word3 word4" | read . . content .
print - "$content"

But this sounds like a problem to me:

As far as i remember the maximum line length for a ksh input line is a system constant and is IIRC 4096 or 8192 characters. If your string is more than 5k characters long a command with this string as argument will either already fail due to shell restrictions or at least be in danger of failing if the string grows over time. The error message will be something like "argument list too long" or something such. You might want to redesign the process which leads to such extraordinary long argument lists.

I hope this helps.

bakunin

My problem is i am unable to test this on any of my boxes as the string is so huge...

i tried few other options and all of them work but the string i used was smaller as compared to one i am referring to.

you guys can try following options:

1> echo $CMD_ARGS |nawk '{$1=" ";sub ("^    ","");print}'

2> echo $CMD_ARGS |cut -d ' ' -f 2-

3> echo $CMD_ARGS |nawk '{print substr($0,index($0," ")+1,length($0))}'

i can't even paste that string here as it would look very weird....i m badly stuck...

by the way,i could not understand 'read' concept in above posts....can you guys explain a bit more ? (or rather paste me the code :stuck_out_tongue: )

so lets create a variable to test your requirements:

switch to ksh93, since ksh can't handle a for loop with a syntax like this:

ksh93
CMD_ARGS=$(for ((i=0;i<20000;i++)) ; do [[ $i = 5 ]] && printf " " ; printf a  ; done )

this little script sets the variable CMD_ARGS to

echo $CMD_ARGS
aaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...................... (19995 times)
echo $CMD_ARGS | read . WHATYOUWANT
(thanks bakunin for that, didn't know that it's possible to use . as variable name ;))
echo $WHATYOUWANT

gives you 19995 times a, so it's possible with read

the maximum size of command arguments on AIX, is set with the ncargs attribute, listed as option of sys0

lsattr -El sys0 -a ncargs

default on my systems is 6, so you have 6x4k blocks=24k=24k characters

if I set the variable to 30k times a, I get the following error message, for every command I want to run:

ksh93: /bin/ls: cannot execute.
[The parameter or environment lists are too long.].

set ncargs to 16 for example, then you wont have problems

and @ ak835:

from the man page of read:

to make sure, set the ifs to " ", before running the read command