another awk question
I have a file called test.txt which has the following data.
35554 the 20343 and 17130 to 15331 of 12130 a I want to divide each element in the first column with the number of total lines in the file i.e 5 in this case. I tried using the following command to do it. awk '{print $1/NR}' test.txt It doesn't work. Could anyone please help. |
Hi,
try this: Code:
awk '{a[FNR]=$1}END{FNR--;for (i=1;i<=FNR;i++){print a[i]/FNR}}' file |
nevermind. i figured out a solution :)
x=wc -l <test awk '{print $1/'$x'}' test i kept using $x instead of '$x' before so i had to resort to using NR to no avail. |
Assuming you still want the rest of the line you could also do:
Code:
awk '{first[NR]=$1;rest[NR]=gensub($1,"",1)}END{for(i=1;i<=NR;i++)print first[i]/NR rest[i]}' test.txt |
All times are GMT -5. The time now is 09:15 AM. |