Discussion: Get previous string
Afficher un message
Vieux 07/01/2008, 20h43   #10
Joseph H. Rosevear
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Get previous string

shulamitm <shulamitmi@bezeq.com> wrote:
> Hello all,


> I have the following line:


> CSM@csUCtn Yes CSM@csUSo No CSM@csUSo Yes


> I need to get the previous string to "No" string.
> In this example: "CSM@csUSo"


> How can I do it (SUN OS)?


> thanks in advance!


Shulamitm,

Here is how I did it. I wrote this shell script (in /tmp/try) and
called "prev":

vvv
#!/bin/sh

prev=""

echo
for field in `echo $1`; do

if [ "$field" = "No" ]; then

echo "field previous to \"No\" is \"$prev\""
fi

prev="$field"
done
^^^

Here are some examples of execution:

vvv
joe@airlink9:/tmp/try$ ./prev "CSM@csUCtn Yes CSM@csUSo No CSM@csUSo Yes"

field previous to "No" is "CSM@csUSo"



joe@airlink9:/tmp/try$ ./prev "No CSM@csUCtn Yes CSM@csUSo No CSM@csUSo Yes"

field previous to "No" is ""
field previous to "No" is "CSM@csUSo"



joe@airlink9:/tmp/try$ ./prev "No CSM@csUCtn Yes CSM@csUSo
No CSM@csUSo Yes Fred
No"

field previous to "No" is ""
field previous to "No" is "CSM@csUSo"
field previous to "No" is "Fred"
^^^

I hope this s.

-Joe
  Réponse avec citation
 
Page generated in 0,04871 seconds with 9 queries