Performing math in a Bash function and declaring it in a variable in 1 line

I would like to make a rowcount file and subtract it from it. I know how to do the first part of getting a string with this function:

zcat filename$today.csv.gz | wc -l 

But how can I subtract one of this value to account for the headers and store it in a variable? I tried

 $(( zcat filename$today.csv.gz | wc -l - 1 )) 

but it does not work.

Should I save the first output of the function as a variable first? Is this a recommended practice?

+5
source share
1 answer

This one-liner can do the job:

 n=$(( $(zcat filename$today.csv.gz | wc -l) - 1 )) 
+7
source

Source: https://habr.com/ru/post/1235153/


All Articles