0

I need to get the name of the file (IN_INK_GOOGLE_20200519.dat) in below string . I want to do it using shellscript. Also, as filename regex conditions are - should start with IN_INK & end with .dat and if it matches more than once, only one match or first match should print. is it possible? ,

echo "-sIN.GOOGLE.IN.INK.INNK.INACC\n-i/am/ft/data/INK/out/GOOGLE_INK/INK/out/IN_INK_GOOGLE_20200519.dat\n-o/apps/tnk/in/download/in/IN_INK_GOOGLE_20200519.dat\n-uinnko1\n-end"

1 Answer 1

1

One solution is to pipe into sed as follows:

echo ... | sed -e 's/[.]dat.*/.dat/' -e 's|.*/||'

To use a "pure shell" solution try the # and % features of variable expansions:

e="-sIN.GOOGLE.IN.INK.INNK.INACC\n-i/am/ft/data/INK/out/GOOGLE_INK/INK/out/IN_INK_GOOGLE_20200519.dat\n-o/apps/tnk/in/download/in/IN_INK_GOOGLE_20200519.dat\n-uinnko1\n-end" 

f="${e%%.dat*}.dat";  #strip trailing clutter after first

echo ${f##*/};    #echo just name
echo IN_INK${f##*/IN_INK}  #variation
Sign up to request clarification or add additional context in comments.

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.