|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
I´m experiencing difficulties trying to make the following lines work properly (ksh): { while read LINE ; do LENGTH=$(expr length "$LINE") END=`expr $LENGTH - 1` VAR=$(expr substr "$LINE" 9 "$END" ) ... } < $FILE I want it to put into VAR the string "$LINE[9,$END]". Even though the command works, it seems to ignore my end range variable "$END" and returns "$LINE[9,$LENGTH]" instead. Any suggestions about the syntax of the end range for this substring command? Thank you by advance! Oh and this is my first post so hello to everybody. |
|
#2
|
|||
|
|||
|
Try this:
while read LINE ; do LENGTH=$(expr length "$LINE") let LEN=LENGTH-9 VAR=$(expr substr "$LINE" 9 "$LEN" ) echo $VAR done << ! 12345678ABCD ! Comments: 1. You do not need the braces for input redirection. The while loop ends in corresponding done. After it you can place the necessary redirection. 2. substr needs the required length as its last argumnet, not the index of the last character required. 3. In ksh you can use the let statement for your calcalations. 4. Have a fun. Ragards ![]() |
|
#3
|
|||
|
|||
|
Thank you very much!
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Substr command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|