Bash - Extracting whole word containing substring

hello.
I get this text when using some command :

S | Name            | Type    | Version | Arch | Repository  
--+-----------------+---------+---------+------+-------------
  | AdobeReader_enu | package | 9.5.4-1 | i486 | zypper_local

I need to get "AdobeReader_enu" from the the pattern "Ado"
something like :

FILE_NAME=$( some_command | grep -o "Ado" )

Any help is welcome.

FILE_NAME=$( some_command | grep -o "Ado[^[:space:]]*" )
1 Like

grep -o "Ado[^[:space:]]*" works for the example but not for a string like xyzAdobeReader_enu .

Great.
Please can you explain --> Ado[[1]]*

Thank you for helping.


  1. :space: ↩︎

[:space:] is a character class that represents tab, newline, vertical tab, form feed, carriage return, and space.

^ represents character not in the list.

* represents zero or more occurrences.

exact.

S | Name            | Type    | Version | Arch | Repository  
--+-----------------+---------+---------+------+-------------
  | AdobeReader_enu | package | 9.5.4-1 | i486 | zypper_local

some_command | grep -o "Rea[[1]]*"

Return :

Reader_enu

So how to improve ?

---------- Post updated at 23:20 ---------- Previous update was at 23:18 ----------

Thank you


  1. :space: ↩︎

try:

grep -o "[^[:space:]]*Rea[^[:space:]]*" 

or

sed -n '/Rea/s/.*\b\(.*Rea\w*\).*/\1/p'

which will also return the word between boundary and end of word. (in case word is wrapped by white space or non white space chars)

1 Like

Thank you every body for helping.