How to slice specific column

Hi,

i have a line where i need to get only the OS version. below is the sample line i have.

i only need this part. OS=MX20000111/RFS00000001

INFO: Thread-92 Partial Message in Queue: .ABCD.APP=5.0.21-20001223.XPIAPP=0054.00F-20200110.XPIKERNEL=000020000.OS=MX20000111/RFS00000001/.PACKAGES=alsa-lib:1.0.0; busybox:1.2.6.2501; captouch-flash:1.0.3.2501; cdgnetcfg:1.1.1.1; cdgnetctrl:1.1.1.1; dropbear:2012.55.3; ecr-lib:1.0.2; fancypants:1.1.1.1; fonts-flash:1.0.10; hantrolib:1.0.6; i2c-tools:1.0.0; kmods:1.1.3; libgpl:1.0.0; libgraphic:1.0.3; libvp:1.0.8; libvpcfg:1.0.5; logapi:1.1.1.1; logo_screen:1.0.0; mxlegacy:1.1.1.1; netutils:1.0.1; openssl:1.0.6; powermgt:1.0.18.2502; secins:1.12.1.1; securemods:1.0.1.1; security:1.3.4.5; security-flash:4.2.6; skeletonfs:1.1.2.3; svcstklibs:1.0.13; vfi-utils:1.2.3.4 vfilib:1.1.2.4; vfimods:1.1.3.4; vfinetctrl:1.0.4; z_ctls_L1:1.0.05; z_vats_unlock_rfs:1.0.0;

Welcome!

What did you attempt?

tried awk and grep

grep -m1 "OS=MX" <file> | awk -F '=' '{print $3, $4}"

but it is giving me the whole line and not the desired column.

You can try the -o grep option, return only the matching portion.
Of course,
grep -o -m1 "OS=MX"
will not match enough - the desired following characters must be specified.
It seems to end with a dot, so use an RE "all not-dot characters"
grep -o -m1 "OS=MX[^.]*"
It's always good to add a boundary, so it wouldn't match e.g. a BOS=MXxx
On the right side there is the dot boundary, on the left side we put a boundary marker (that does not match a character ).
grep -o -m1 "\bOS=MX[^.]*"
If you do not want the tailing slash then the tricky solution is
grep -o -m1 "\bOS=MX[^.]*[^/.]"
A boundary followed by OS=MX followed by any amount of not-dot characters followed by a neither-slash-nor-dot character.

1 Like

@ernesto022483
please start using markdown code tags when posting code/data samples - the markdown usage is outlined here on the community welcome page.
I've edit your OP for now.

thanks @vgersh99

This topic was automatically closed 300 days after the last reply. New replies are no longer allowed.