[Bash regex] Need some help with regular expression

General support questions
Post Reply
Posts: 1
Joined: 2020/05/21 07:04:50

[Bash regex] Need some help with regular expression

Post by lucky_strike » 2020/05/21 07:27:28

I am new to forums and Id like to ask a question. I hope this is the right place to ask that question.

Im writing some scripts in CentOS 7 and I need some help with regular expressions. I have read a lot but my tests gone bad.

Ive got output copied into text file
BRIDGE-MIB::dot1dTpFdbPort.'..L2G.' = INTEGER: 29
BRIDGE-MIB::dot1dTpFdbPort.'..$..F' = INTEGER: 3
What I want is to get the red strings into array, no matter how many similar lines I get.

I have tried something like this:

Code: Select all

array=($(cat test.txt | grep -o -E \'[!-~]{6}\' ))
But its not working. Desired result is to get array with items that are in red in my example. It would be good if there were no ' chars.

Please help me, Thank You

User avatar
Posts: 2774
Joined: 2007/12/11 08:17:33
Location: Finland

Re: [Bash regex] Need some help with regular expression

Post by jlehtone » 2020/05/21 12:27:45

1. This question is not about CentOS. There ought to be more specific Fora out there.

2. This question is not about Bash either. Bash has only "pattern matching" / "globbing". See https://www.tldp.org/LDP/abs/html/globbingref.html

3. Grep, sed, awk, perl, etc do regular expressions (RE), but there are many dialects of RE.

4. That said, this is greedy but might suffice:

Code: Select all

sed "s/.*'\(.*\)'.*/\1/" test.txt

Post Reply

Return to “CentOS 7 - General Support”