0

Im working with Ksh shell. In my script i have a variable in it which contains mutiple strings, when i echo it it following out put (using echo $serviceList) xoc.hw.megt.Manager xoc.ssion.ZConionClient xoc.svc.onLifecycle xoc.job.ZSumStateHook xoc.hw.cor.ZBulations xoc.hw.megt.Manager xoc.hw.cor.mmgt.ZMemoro xoc.cot.fdhug

now i have to find is there any string which is repeating if it is repeating then it should give me alert that string is repeated. e.g. In above example xoc.hw.megt.Manager is repeating.

Thank in advance.

2 Answers 2

1

This may help http://www.linuxquestions.org/questions/programming-9/shell-script-to-compare-blocks-of-strings-435211/

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the link. But im unable to transvers through the variable to get each string separatly.
serviceList=${serviceList// /$'\n'} for word in $serviceList; do echo "$word" done
0

The simplest way is perhaps to use command uniq -d, which will print only duplicate lines, if you can use it like, i.e.

$ my_script | uniq -d

And if you have to implement this within the script itself, then the previous answer gets it done.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.