I need to get a particular string from a text file. the content of my file is below :
Components at each of the following levels must be built before components at higher-numbered levels. 1. SACHHYA-opkg-utils master@964c29cc453ccd3d1b28fb40bae8df11c0dc3b3c SACHHYA-web-SABARMATI-ap-page master@3bdc2dc1e5cee745cfced370201352045cd57195 SACHHYA-web-update-page master@24b0ffaad4d130ae5a2df0e470868846c7888392 SACHHYAWebMonaco Release/MR1_2019/3.0.7-570+36a238d googletest-qc8017_32 branches/googletest@2692 LpmMfgTool Release/master/0.0.1-4+34833d6 opensource-avahi-qc8017_32 Release/SACHHYA-master/v1.0-4-gb70507e opensource-OpenAvnuApple-qc8017_32 Release/SACHHYA-master/v1.0-1766-g1098033 opensource-opkg-qc8017_32 Release/SACHHYA-dev/v0.3.6.2-2-gb1e1aba opensource-unzip-qc8017_32 Release/master/v6.0.0 opensource-util-linux-qc8017_32 Release/SACHHYA-master/1.5.0-10+877ade5 opensource-zip-qc8017_32 Release/master/v3.0.0 product-startup Release/master/4.0.0-5+5179185 ProductControllerCommon master@a1e71509aaaa9cf7a9e70d4e9c7bfc80d76e13a2 ProductUIAssets master@220944def647a72ce0194d43ef23f1d3fe146987 proprietary-airplay2-qc8017_32 Release/SACHHYA-master/2.0.2-15-g88c1c1d SABARMATI-HSP-Images Release/master/4.4 SABARMATI-Toolchain Release/master/4.4 SABRMATILPM trunk@3408 SABARMATILpmTools @3604 SABARMATILpmUpdater Release/master/1.0.0-69+a38d6c8
The command that i am trying is :
awk /SACHHYAWebMonaco/ MyFile.txt
Using this command, I am able to get that particular line in which my string is present. Here is the result of the awk
command :
SACHHYAWebMonaco Release/MR1_2019/3.0.7-570+36a238d
What I want to grep is only “3.0.7” (which is the version) from that line .
Can anyone have any suggestion to do that?
Advertisement
Answer
You can use /
and -
as field separators and print the third field.
This assumes the format of the lines and position of the information you seek will always be such.
$ awk -F[/-] '/SACHHYAWebMonaco/ {print $3}' file 3.0.7