1
I have a file which has many lines of the format:
bc("STG1/Phone") = {type=bana_pub; cbb=12.354; abb=0.0}`
I'm looking to extract cbb=12.354;
. Currently, I'm doing the following:
cat input_file.txt | grep cbb | awk -F " " '{ print $4 }'`
The problem is that my approach is location specific i.e. assumes it's always 4th field. How do I extract text of the form cbb=
knowing after the =
it could be any length and the semi-colon ;
is optional. The only guarantee I have is that the term cbb=12.354;
will be surrounded by whitespace if that helps. The file in future may be of the format:
bc("STG1/Phone") = {type=bana_pub; cbb=12.354; abb=0.0}
bc("STG1/Phone") = {type=bana_pub; abb=0.0; cbb=12.354}
My gut tells me regex is probably the way to go, but I generally try and avoid it if I can as I prefer simple matching tools (which I understand better).
Thanks in anticipation for your help.
A one-liner is mandatory or a bash script is allowed? – Alessandro Carini – 2017-10-27T12:59:59.227
Preference is one liner but I'm looking to learn - so yes bash scripts are allowed. – fswings – 2017-10-27T13:08:00.273
You should add a more complete input file snippet that includes lines where the desired string is at different positions. – simlev – 2017-11-02T09:17:17.280