0

Below are the file contents:

{30001002|XXparameter|XSD_LOC|$\{FILES_DIR\}/xsd/EDXFB_mbr_demo.xsd|3|2|$|@{0|}}
{30001002|XXparameter|source_files|$XSD/EDXFB_mbr_demo.xsd|3|1|l|@{0|}}

I trying to accomplish below using awk: Firstly I want to search for string Pattern "EDXFB*.xsd". If exists, then extract the strings that starts with "EDXFB" and ends with ".xsd"

Output:

EDXFB_mbr_demo.xsd
EDXFB_mbr_demo.xsd
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105

3 Answers3

2

The basic awk pattern to extract the expression and print out matched data is following:

gawk 'match($0, /EDXFB.+\.xsd/, a) { print a[0] }'

Though, you should really spend some time reading awk manual.

And the regular expression could be changed to /EDXFB[a-z_]+\.xsd/ if it contains only lower-cased characters and _.

[EDIT]: Updated with cleaner code from @JID. Thanks :)

plaes
  • 31,788
  • 11
  • 91
  • 89
1

Here is one way to do it:

awk -F/ '/EDXFB.*\.xsd/ {split($NF,a,"|");print a[1]}' file
EDXFB_mbr_demo.xsd
EDXFB_mbr_demo.xsd

It separate the line by / then print last field until |

Jotne
  • 40,548
  • 12
  • 51
  • 55
1

In your example, probably grep would do what you want:

grep -o 'EDXFB.*\.xsd'
JJoao
  • 4,891
  • 1
  • 18
  • 20
  • 1
    Note this requires GNU grep –  May 05 '15 at 08:06
  • 1
    @JID, I was planning to write a more complex version `EBXFB.*?\.xsd(?=\|)` but I believe a simple grep is what OP is looking for... – JJoao May 05 '15 at 08:10