commit 8b90b1d85fb937327964a0e9f1de2b495d3dbd90
parent 3def0c99509cccc70f9ce24ef1d1fd295264041c
Author: root <root>
Date: Tue, 22 Apr 2025 11:35:41 +0200
new awk script
Diffstat:
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/awk/fan_out_chunks.awk b/awk/fan_out_chunks.awk
@@ -0,0 +1,44 @@
+#!/bin/awk
+
+#Another awk script for reorganizing data in CSV files.
+#The necessity here was similar to some of the other files in here,
+#the data format was too awkward for some process to work with, and this was the quickest way to fix it.
+
+BEGIN{
+ FS="@|;";
+}
+{
+ swp = $1";"$2";"$3";"$4";"$5";"$6;
+ tmp = swp;
+ c = 0;
+ for (i = 7; i <= NF; i++) {
+ c++;
+ tmp = tmp";"$i;
+ if (c % 5 == 0) {
+ print tmp;
+ tmp = swp;
+ }
+ }
+}
+
+#HOW IT WORKS
+
+#2927;1;CH0006539198;EUR;200;48543;968@0@91@76@3000;969@0@91@77@1000;970@0@91@78@100
+#3824;1;DE000A1EWWW0;EUR;200;48543;968@0@91@76@3000;969@0@91@77@1000;970@0@91@78@100
+
+#2927;1;CH0006539198;EUR;200;48543;968;0;91;76;3000
+#2927;1;CH0006539198;EUR;200;48543;969;0;91;77;1000
+#2927;1;CH0006539198;EUR;200;48543;970;0;91;78;100
+#3824;1;DE000A1EWWW0;EUR;200;48543;968;0;91;76;3000
+#3824;1;DE000A1EWWW0;EUR;200;48543;969;0;91;77;1000
+#3824;1;DE000A1EWWW0;EUR;200;48543;970;0;91;78;100
+
+# FS="@|;" -> Delimiter is either @ or ;
+# take first 6 fields, save them into a variable called swp to turn them into a constant
+# fields 7 to end (NF) fanned out into groups of 5, prefixed by constant swp
+# on every 5th appended field, print line and reset buffer
+# it's possible to change the magic number 5 by adding a variable from bash
+# into BEGIN block -> if (chunk=="") {chunk=5}
+# if (c % 5) -> if (c % chunk)
+# call the awk script with -v chunk=<NUMBER>
+
diff --git a/awk/reorganize_groups.awk b/awk/reorganize_groups.awk
@@ -63,3 +63,20 @@ BEGIN {
END {
printf "\n"; # Clean newline at end
}
+
+
+#HOW IT WORKS
+#cat file1
+#dsfs,2@44,2@55,3@66,3@88,3@89,3@90,3@91,4@56,4@777,4@65,5@776,5@545
+#afsf,1@00,1@99
+#bdsa,2@323,2@212,6@432,6@2188
+
+#awk -f reorganize_groups.awk <FILE>
+#dsfs;2;;44;55;
+#dsfs;3;;66;88;89;90;91;
+#dsfs;4;;56;777;65;
+#dsfs;5;;776;545;
+#afsf;1;;00;99;
+#bdsa;2;;323;212;
+#bdsa;6;;432;2188;
+