Bash scripting 16 – Using data files 2
So, carrying on from the previous article(s). I am going to be using gnuplot and awk, and see what I can do with the data generated by my script.
It would be useful to be able to remove content in the file we are using with awk, so new data is not added to existing data.
We can do this by running:-
echo " " > log.csv
This should ensure the file is empty
we can then rerun
./gencsv1.sh
And check contents with
echo csv.log
So according to the article, we can list the data in the 2nd column
awk -F, '{ print $2}' log.csv
2
7
14
4
5
7
17
19
0
19
and on a similar note, to list what is in the first column
awk -F, '{ print $1}' log.csv
and we can calculate the sum using
awk -F, '{ sum +=$2} END { print sum }' log.csv
94
and the average
awk -F, '{ sum +=$2} END { print sum/NR }' log.csv
8.54545
Chat
I am on the Devon and Cornwall Linux user group mailing list and also their matrix channel as zleap, it is better to ask there, that way others can answer too.
Tags
#Bash,#Bashscripting,#Files,#UsingDataFiles,#Data,#BashScripting
Mastodon | ShellLabs | Join Mastodon |