@@ -13,16 +13,8 @@ object AwkExample : OneLinerContext(args) {
1313 override fun apply (lines : Sequence <String >) {
1414 lines.split().map({ it[1 ] }, { it[2 ] }).print ()
1515
16-
1716 lines.split().filter { it[3 ].matches(" UA" .toRegex()) }.print ()
1817
19- (1 .. 3 ).asSequence().toList().toTypedArray()
20- // remove header
21-
22- val foo = arrayOf(* arrayOf(1 .. 3 ).toList().toTypedArray())
23-
24-
25-
2618 lines.drop(1 ).split().filter { it[3 ].matches(" UA" .toRegex()) }.print ()
2719
2820
@@ -40,6 +32,7 @@ object AwkExample : OneLinerContext(args) {
4032 lines.split().map { it.toMutableList().apply { removeAt(3 ) } }.print ()
4133
4234
35+
4336 // http@ //tuxgraphics.org/~guido/scripts/awk-one-liner.html
4437 // Print the next two (i=2) lines after the line matching regexp:
4538 // awk '/regexp/{i=2;next;}{if(i){i--; print;}}' file.txt
@@ -62,7 +55,6 @@ object AwkExample : OneLinerContext(args) {
6255 // awk '{print FNR "\t" $0}'
6356 lines.mapIndexed { num, line -> num.toString() + " " + line }.print ()
6457
65-
6658 // Remove duplicate consecutive lines (uniq):
6759 // awk 'a !~ $0{print}; {a=$0}'
6860
@@ -85,6 +77,18 @@ object AwkExample : OneLinerContext(args) {
8577
8678 lines.dropWhile { it.startsWith(" foo" ) }.takeWhile { it.startsWith(" bar" ) }.print ()
8779
80+
81+ // Print the last field in each line:
82+ // awk -F: '{ print $NF }' file.txt
83+ lines.split(" :" ).map { it[it.size - 1 ] }.print ()
84+
85+
86+
87+ // Prints Record(line) number, and number of fields in that record
88+ // awk '{print NR,"->",NF}' file.txt
89+ lines.split().mapIndexed { index, row -> index.toString() + " -> " + row.size }.print ()
90+
91+
8892 val arg by lazy { resolveArgFile(args) }
8993 arg.filter { true }.print ()
9094 }
0 commit comments