0

I have a file with the following contents

abc_cde_app_13.5.0.10
abc_cde_app_13.5.0.10.xml
abc_cde_app_13.5.0.10_log.url
abc_cde_app_13.5.0.10_note.xml

The numbers may change and are not standard. And I wish to pick only the 1st one. I am passing all three in to the variable $file. But its showing Version found for all three files. How can I get it only for the 1st

if echo "$file" | grep -E "abc_cde_APP"; then
     echo "Version found: $file"
else
 echo "File not found"

1 Answer 1

1

how about this:

grep 'abc_cde_app_[^_]*$'

it works for your example:

kent$  echo "abc_cde_app_13.5.0.10
abc_cde_app_13.5.0.10_log.url
abc_cde_app_13.5.0.10_note.xml"|grep 'abc_cde_app_[^_]*$'   
abc_cde_app_13.5.0.10
Sign up to request clarification or add additional context in comments.

2 Comments

Hi,It worked n,But there is one more file abc_cde_app_13.5.0.10.xml Its picking that also. Sorry I didnt mention it before..I will update my question as well
Try this :^abc_cde_app_[0-9.]*$

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.