Skip to content

Commit ea26ca1

Browse files
committed
added disabled LAST field
1 parent 0acf9bf commit ea26ca1

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/main/kotlin/kscript/text/Tables.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,9 @@ fun Sequence<Row>.select(columns: ColSelect): Sequence<Row> {
131131
}
132132

133133

134+
// http://www.thegeekstuff.com/2010/01/8-powerful-awk-built-in-variables-fs-ofs-rs-ors-nr-nf-filename-fnr/?ref=binfind.com/web
135+
//NF Example: Number of Fields in a record
136+
//val LAST = Integer.MIN_VALUE
137+
134138
// todo add krangl ColNames interface here
135139

src/test/kotlin/kscript/examples/AwkComparison.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)