0

I have a file as below

<SHORTCUT COMMENTS ="" DBDNAME ="xsxx_db2" FOLDERNAME ="XS_SHARED" NAME ="Shortcut_to_xx_CNTC_T" OBJECTSUBTYPE ="Source Definition" OBJECTTYPE ="SOURCE" REFERENCEDDBD ="xsxx_db2" REFERENCETYPE ="LOCAL" REFOBJECTNAME ="XSC_CLNT_CNTC_T" REPOSITORYNAME ="xxxx" VERSIONNUMBER ="2"/>
<SHORTCUT COMMENTS ="" FOLDERNAME ="MK_SHARED" NAME ="Shortcut_to_CIF_FF_MOB_NBR" OBJECTSUBTYPE ="Target Definition" OBJECTTYPE ="TARGET" REFERENCETYPE ="LOCAL" REFOBJECTNAME ="CIFXx_NBR" REPOSITORYNAME ="eim_xx" VERSIONNUMBER ="1"/>
<SHORTCUT COMMENTS ="" DBDNAME ="FlatFile" FOLDERNAME ="XS" NAME ="Shortcut_to_xxFF_TX" OBJECTSUBTYPE ="Source Definition" OBJECTTYPE ="SOURCE" REFERENCEDDBD ="FlatFile" REFERENCETYPE ="LOCAL" REFOBJECTNAME ="DXX_FF_TX" REPOSITORYNAME ="xxxx" VERSIONNUMBER ="1"/>

I need to extract the values in "" that follows the string FOLDERNAME =

Output needed is

XS_SHARED 
MK_SHARED
XS

4 Answers 4

1

You can use awk:

awk -F '^.*FOLDERNAME *= *"|"' '{print $2}' file
XS_SHARED
MK_SHARED
XS

It is usually better to use DOM parsers for XML rather than using awk/sed/grep though.

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

Comments

1

With sed:

sed 's/.*FOLDERNAME *= *"\([^"]*\)".*/\1/' file

Comments

1
grep -oP '(?<=FOLDERNAME =").+?(?=")' file

Comments

1

Actually you can do it with awk using file separator option:

awk 'BEGIN { FS = "FOLDERNAME =" } ; { print $2 }' file | awk -F'"' '{print $2}'

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.