How to check a string and get a substring in bash

hi experts.
pls help

Sample input file:      
[changed] parent_dir/app_name/comp_name/process/ccc/sca_aws.approval.test.updatecriteria_rev1.0.jar  ( size 144280 : 144280 )
[changed] parent_dir/app_name/comp_name/ui/xxx/aws.workflow.ui.loans.ear/aws.cz.ui.template.mar  ( size 2644 : 2644 )
[changed] parent_dir/app_name/comp_name/process/xxx/sca_aws.cz_rev1.0.jar/xsl/aws.xsl  ( size 9440 : 9464 )
[changed] parent_dir/app_name/comp_name/process/xxxx.zip/sca_aws.approval.test.maintain_rev1.0.jar  ( size 143643 : 143643 )
[changed] parent_dir/app_name/comp_name/ui/ggggg/aws.workflow.ear/aws.cz.ui.view.account.mar  ( size 12904 : 12904 )
[changed] sharedResources.jar/process/xsd/me/test.xsd  ( size 3001 : 2947 )
[changed] aws.workflow.ui.test.war/WEB-INF/classes/com/app_name/ui/test/event/test.class  ( size 3426 : 4364 )

output trying to achive:
process=sca_aws.approval.test.updatecriteria_rev1.0.jar,sca_aws.cz_rev1.0.jar,sca_aws.approval.test.maintain_rev1.0.jar
ui=aws.workflow.ui.loans.ear,aws.workflow.ear
war=aws.workflow.ui.test.war

As you can see,
if I find a string "process" then I have to get the jar name
if I find a string "ui" then ear name
same for war

I would request, if you could help with individual script for each expression. eg. process, ui, war

thanks in advance
enthuguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
#!/bin/bash
while read line ; do
  case "$line" in
  */process/*.jar*) s=${line%%.jar*}; process+=${s##*/}.jar, ;;
  */ui/*.ear*) s=${line%%.ear*}; ui+=${s##*/}.ear, ;;
  *.war/*) s=${line%%.war*}; war+=${s##* }.war, ;;
  esac
done <<EOF
[changed] parent_dir/app_name/comp_name/process/ccc/sca_aws.approval.test.updatecriteria_rev1.0.jar  ( size 144280 : 144280 )
[changed] parent_dir/app_name/comp_name/ui/xxx/aws.workflow.ui.loans.ear/aws.cz.ui.template.mar  ( size 2644 : 2644 )
[changed] parent_dir/app_name/comp_name/process/xxx/sca_aws.cz_rev1.0.jar/xsl/aws.xsl  ( size 9440 : 9464 )
[changed] parent_dir/app_name/comp_name/process/xxxx.zip/sca_aws.approval.test.maintain_rev1.0.jar  ( size 143643 : 143643 )
[changed] parent_dir/app_name/comp_name/ui/ggggg/aws.workflow.ear/aws.cz.ui.view.account.mar  ( size 12904 : 12904 )
[changed] sharedResources.jar/process/xsd/me/test.xsd  ( size 3001 : 2947 )
[changed] aws.workflow.ui.test.war/WEB-INF/classes/com/app_name/ui/test/event/test.class  ( size 3426 : 4364 )
EOF
process=${process%,}
ui=${ui%,}
war=${war%,}
echo $process
echo $ui
echo $war
0
woolmilkporcCommented:
This is awk.

process:

awk '/\/process/ {split($2,A,"/"); for(n in A) if(A[n]~".jar") O=O A[n]","} END {if(O!="") {sub(",$","",O); print "process="O}}' inputfile

ui:

awk '/\/ui/ {split($2,A,"/"); for(n in A) if(A[n]~".ear") O=O A[n]","} END {if(O!="") {sub(",$","",O); print "ui="O}}' inputfile

war:

awk '/war/ {split($2,A,"/"); for(n in A) if(A[n]~".war") O=O A[n]","} END {if(O!="") {sub(",$","",O); print "war="O}}' inputfile


In the "process" case: How should we handle this line?

[changed] sharedResources.jar/process/xsd/me/test.xsd  ( size 3001 : 2947 )

My "process" awk above will show the contained .jar file "sharedResources.jar", but your example output doesn't mention it.
If you really don't want to see "sharedResources.jar" change the "process" version like this:

awk '/\/process\/.*jar/ {split($2,A,"/"); for(n in A) if(A[n]~".jar") O=O A[n]","} END {if(O!="") {sub(",$","",O); print "process="O}}' inputfile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
enthuguyAuthor Commented:
Thanks very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.