0

How can I extract words which contains the pattern "arum" from the following line:

Agarum anoestrum  alabastrum sun antirumor alarum antiserum ambulacrum antistrumatic Anatherum antistrumous androphorum antrum 4. foodstuff foody nonfood Aplectrum 

So words like sun, 4., foody, nonfood should be removed.

Matt
  • 14,906
  • 27
  • 99
  • 149

3 Answers3

0

You can use grep:

echo "Agarum anoestrum sun" | tr ' ' '\n' | grep "arum"

tr is used to split the input string in one word per line, since grep operates on a per-line basis and would display the whole line.
If you want the output to be in one line again, use:

echo "Agarum anoestrum sun" | tr ' ' '\n' | grep "arum" | tr '\n' ' '
Tim Zimmermann
  • 6,132
  • 3
  • 30
  • 36
0

Using grep -Eo:

grep -Eo 'a[[:alnum:]]*rum' file
arum
anoestrum
alabastrum
antirum
alarum
antiserum
ambulacrum
antistrum
atherum
antistrum
androphorum
antrum
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Try:

echo Agarum anoestrum alabastrum sun antirumor alarum antiserum ambulacrum antistrumatic Anatherum antistrumous androphorum antrum 4. foodstuff foody nonfood Aplectrum | awk '{for (i=1;i<NF;i++) { if (match($i, "[aA][[:alnum:]]*[rR][uU][mM]") != 0) { printf ("%s ", $i) }} print}'
SMA
  • 36,381
  • 8
  • 49
  • 73