Tell me if I want to execute this command:
(cat file | wc -l)/2
and save it in a variable, for example, in the middle, how would I do it?
I know this is just not the case
$middle=$(cat file | wc -l)/2
so how can i do this?
middle=$((`wc -l < file` / 2))
middle=$((`wc -l file | awk '{print $1}'`/2))
, Bash , , .
middle=($(wc -l file)) # create an array which looks like: middle='([0]="57" [1]="file")' middle=$((middle / 2)) # do the math on ${middle[0]}
:
((middle /= 2))
$
mid=$(cat file | wc -l) middle=$((mid/2)) echo $middle
. , , , Bash, ?
awk.
middle=$(awk 'END{print NR/2}' file)
"wc", .
linec(){ i=0 while read -r line do ((i++)) done < "$1" echo $i } middle=$(linec "file") echo "$middle"
Source: https://habr.com/ru/post/1733971/More articles:push_back for a vector - c ++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1733967/send-keyboard-and-mouse-events-to-flash-movie&usg=ALkJrhiY2TLXQ4Ab2u8LS3DXhdYa9p0XdASend signals via USB using cocoa? - xcodeWhat is the best way to update ASP.NET web application dlls? - asp.netCan you create a plug-in for Windows Explorer using .net? - windowsSharePoint TimerJobs and Streams - sharepointWill using WSDL to generate REST clients the wrong way? - javaActionScript 3: Memory Leak in Server Poll View Application - memory-leaksProblem with StringBuilder and JSON - jsonthoughts on managing an asp.net grid - asp.netAll Articles