From 289c9d8f7dd54097cd69bd170c57b0b7f79e681c Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 18 Mar 2024 18:15:48 +0100 Subject: [PATCH] 'Added simple AWK scripts;' --- 04_AWK/1.awk | 17 +++++++++++++++++ 04_AWK/2.awk | 16 ++++++++++++++++ 04_AWK/3.awk | 17 +++++++++++++++++ 04_AWK/countries.csv | 2 +- 04_AWK/stars/awk_excercises.txt | 4 ++-- 5 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 04_AWK/1.awk create mode 100644 04_AWK/2.awk create mode 100644 04_AWK/3.awk diff --git a/04_AWK/1.awk b/04_AWK/1.awk new file mode 100644 index 0000000..26ca627 --- /dev/null +++ b/04_AWK/1.awk @@ -0,0 +1,17 @@ +BEGIN { + print "POCZATEK" + sum = 0.0; +} + +{ + country = $1; + if ($2 > 40) + print country, $2, NF + + sum += $2; +} + +END { + print "KONIEC" + print "Sum of the 2nd columns is ", sum +} \ No newline at end of file diff --git a/04_AWK/2.awk b/04_AWK/2.awk new file mode 100644 index 0000000..11b029e --- /dev/null +++ b/04_AWK/2.awk @@ -0,0 +1,16 @@ +BEGIN { + sum = 0.0; + l = 0; +} + +{ + if ($2 > 40 && l > 0) + print "Country", $1, "has", $2, " mln of people, ", "nr of all columns=", NF + + sum += $2; + l++; +} + +END { + print "Num of all people is", sum +} \ No newline at end of file diff --git a/04_AWK/3.awk b/04_AWK/3.awk new file mode 100644 index 0000000..bd25607 --- /dev/null +++ b/04_AWK/3.awk @@ -0,0 +1,17 @@ +BEGIN { + sum = 0.0; +} + +{ + pop = $2; + if ($2 > 40 && $2 < 4000) { + print $2, pop, NF; + print $2, pop, NF; + } + + sum += pop; +} + +END { + print "Sum of all people is ", sum +} \ No newline at end of file diff --git a/04_AWK/countries.csv b/04_AWK/countries.csv index cb1d0d3..0d4d37b 100644 --- a/04_AWK/countries.csv +++ b/04_AWK/countries.csv @@ -1,4 +1,4 @@ -#name population area +# name population area Poland 38 360 Poland 38 360 Germany 78 500 \ No newline at end of file diff --git a/04_AWK/stars/awk_excercises.txt b/04_AWK/stars/awk_excercises.txt index 3461acf..e728e0d 100644 --- a/04_AWK/stars/awk_excercises.txt +++ b/04_AWK/stars/awk_excercises.txt @@ -16,6 +16,6 @@ So, BH formes if the type was not 14 in column 17, but in the same line, in the New task -4. Test, in which places all the mergers take place. +4. Test in which places all the mergers take place. -A merger is an even in which there non-zero value in inter** columns. If there some value in such a column it means that two or more stars merged together, creating a new object. The position in which it took place in star cluster is denoted with the column 'r1'. Compute a histogram for such events for any fiven timestep. Write everything into one file. \ No newline at end of file +A merger is an even in which there non-zero value in inter** columns. If there some value in such a column it means that two or more stars merged together, creating a new object. The position in which it took place in star cluster is denoted with the column 'r1'. Compute a histogram for such events for any given timestep. Write everything into one file in order to plot it. \ No newline at end of file