I'm trying to select a specific section of a specific line within a file.
For instance, I want to isolate the first line of text from a file and get the numeric value of rate
without the trailing kbit
text.
Sample file contents:
tc class add dev br-lan parent 1:1 classid 1:2 htb rate 100kbit ceil 100kbit
tc class add dev br-lan parent 1:1 classid 1:3 htb rate 200kbit ceil 200kbit
tc class add dev br-lan parent 1:1 classid 1:4 htb rate 300kbit ceil 300kbit
I would like to select the data between "rate " (notice the space after rate) and "kbit" based on the line number, then store it as a variable.
Expected Result:
Effectively, I would like to retrieve the results based on, for example; line 1:
100
Then store this value as a variable.
This won't work with substr, as shown here: http://php.net/manual/en/function.substr.php as the length of the integer retrieved may not always be the same length.
File path:
../etc/init.d/bandwidthlimiters/rulestest