extract string within parentheses

Help for MX Fluxbox
When asking for help, use Quick System Info from MX Tools. It will be properly formatted using the following steps.
1. Click on Quick System Info in MX Tools
2. Right click in your post and paste.
Message
Author
User avatar
Jerry3904
Administrator
Posts: 23267
Joined: Wed Jul 19, 2006 6:13 am

extract string within parentheses

#1 Post by Jerry3904 »

<I did a web search on this but solutions I found didn't seem to work>

Now looking at an easier way to do MXFB menu translations that begins by extracting the "name" within parentheses from one file and lists them in another. For instance, this submenu:

Code: Select all

    [submenu] (Docks)
        [exec] (Default) {~/.fluxbox/scripts/DefaultDock.mxdk}
        [exec] (Tint2) {mxfb-tint2-manager}
        [separator]
        [exec] (Dockmaker) {mx-dockmaker}
    [end]
...would produce this:

Code: Select all

Docks
Default
Tint2
Dockmaker\
It would be even better if I could list 4 files in a single command, but they are short enough that it isn't necessary.

Thanks for any help.
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
Jerry3904
Administrator
Posts: 23267
Joined: Wed Jul 19, 2006 6:13 am

Re: extract string within parentheses

#2 Post by Jerry3904 »

Did we do this before?
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
Jerry3904
Administrator
Posts: 23267
Joined: Wed Jul 19, 2006 6:13 am

Re: extract string within parentheses

#3 Post by Jerry3904 »

Wait a minute, this seems to work:

Code: Select all

sed -E -n 's/.*\((.*)\).*$/\1/p' file1 file2
It does pick up the language codes in settings, but those are easy to spot and remove

Source: https://stackoverflow.com/questions/544 ... x-terminal
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
dolphin_oracle
Developer
Posts: 22342
Joined: Sun Dec 16, 2007 12:17 pm

Re: extract string within parentheses

#4 Post by dolphin_oracle »

Code: Select all

grep -oP '\(\K[^)]+' inputfile > outputfile
http://www.youtube.com/runwiththedolphin
lenovo ThinkPad X1 Extreme Gen 4 - MX-23
FYI: mx "test" repo is not the same thing as debian testing repo.

User avatar
Jerry3904
Administrator
Posts: 23267
Joined: Wed Jul 19, 2006 6:13 am

Re: extract string within parentheses

#5 Post by Jerry3904 »

Thanks.
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
i_ri
Posts: 1106
Joined: Tue Jun 30, 2015 12:26 am

Re: extract string within parentheses

#6 Post by i_ri »

Hello Jerry3904 and dolphin_oracle
mxfb-menu-gen places a space between name end and paren,
so the list of names each has a space at the end.
Is that okay for the intended list?
A submenu name has not a space at the end, usually.
is that okay for your purpose?

The outputfile can grep for the space[last] will ignore the submenu names that have no space at the end. (?) if there is a use for this distinction?
or you may wish take that space off the end(?)

(trying to say, avoid reuse of this name list into menu-gen with list name having trailing space )
In /mxflux/menu-translations i do not see trailing spaces. however there is extra paren in out-of-sight_pt

User avatar
Jerry3904
Administrator
Posts: 23267
Joined: Wed Jul 19, 2006 6:13 am

Re: extract string within parentheses

#7 Post by Jerry3904 »

@i_ri Not sure ATM, will look later
****************
I ended up using this procedure for best results: group the 4 menus into a working location, open a terminal there, and run

Code: Select all

sed -E -n 's/.*\((.*)\).*$/\1/p' menu-mx appearance settings out-of-sight > menunames.txt
The grep command inserted the file name at the beginning of each line, otherwise the outputs were identical with 96 strings
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

Post Reply

Return to “MX Fluxbox Official Release”