I don't think we can accomplish this with OOTB feature. By looking into excel formula, I was hoping to accomplish this with JSON column formatting. However, the issue is replace() function replaces only the first occurrence of '\n'. You can repeat replace() function though if you know the expected max line count, but will not be reliable.
You may try using MS Flow/Power Automate to accomplish this.
Excel Formula:
=LEN(A2)-LEN(SUBSTITUTE(A2,CHAR(10),""))+1
JSON Column Formatting:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=indexOf([$Multiline] + '^', '^') - indexOf(replace([$Multiline], '\n', '') + '^', '^') + 1"
}
However, you can repeat replace() function to a known max number like below to accomplish your goal. But the result count might not be accurate if the actual line number is > then the number of times replace() used in the JSON.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=indexOf([$Multiline] + '^', '^') - indexOf(replace(replace(replace(replace(replace(replace([$Multiline], '\n', ''), '\n', ''), '\n', ''), '\n', ''), '\n',''), '\n','') + '^', '^') + 1"
}