Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I hope someone can help me in writing a shell script to do the following,
- in a file there are multiple lines, and some of them have the following,
Mxxx a=6 b=2 c=2- I want to parse this file and if the line has parameter "b" then it will chnage the values as follows,
Mxxx a=6/b b=2 c=2*b

If there is a parameter "b" on a line, there will always be two other parameters on the same line "a" and "c". Then take the value of parameter "b" which is 2 in this example, and divide the value of "a" ( which is 6 in this case) by the value of "b" (6/2), and multiply the value of "c" (which is 2 in this case) by the value of "b" (2*2).
The line that contains these parameters will look like this,
Mxxx a=6 b=2 c=2
The values of b and c are always integers, but sometimes indicated by 6.0 instead of just 6.
The value of "a" can be a decimal like 4.5u where u is for micron, sometimes the value of "a" is a variable that is defined somewhere else in the file.
Then do the same procedure to every line that has a parameter "b" in the whole file.

The decimals are the hardest part, since maths on unix tend to be non-decimal based. Let's start with non-decimals:
You can get the values of those letters you look for (a, b and c) like this:
<whatever command> | awk -F"a=" ' { print $2 } ' | awk ' { print "a=" $1 } '

![]() |
printing all lines after ...
|
Separating the Columns ba...
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |