jcdole
1
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.
Yoda
2
FILE_NAME=$( some_command | grep -o "Ado[^[:space:]]*" )
1 Like
rdrtx1
3
grep -o "Ado[^[:space:]]*"
works for the example but not for a string like xyzAdobeReader_enu
.
jcdole
4
Great.
Please can you explain --> Ado[]*
Thank you for helping.
Yoda
5
[: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.
jcdole
6
exact.
S | Name | Type | Version | Arch | Repository
--+-----------------+---------+---------+------+-------------
| AdobeReader_enu | package | 9.5.4-1 | i486 | zypper_local
some_command | grep -o "Rea[]*"
Return :
Reader_enu
So how to improve ?
---------- Post updated at 23:20 ---------- Previous update was at 23:18 ----------
Thank you
rdrtx1
7
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
jcdole
8
Thank you every body for helping.