-
Notifications
You must be signed in to change notification settings - Fork 2
/
lines.bat
executable file
·45 lines (38 loc) · 852 Bytes
/
lines.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
::#! 2>/dev/null || echo "
@echo off
call scala -savecompiled %~f0 %*
goto :eof
" >//null
#!/bin/sh
exec scala -savecompiled "$0" "$@"
::!#
val enc = args match {
case Array() => "UTF-8"
case Array(fileEncoding) => fileEncoding
case _ => {
println("""
| Read lines from files
| Usage:
| lines
| lines "<file_encoding>"
| Examples:
| (echo bar.txt && echo baz.txt) | lines
| first line in bar
| second line in bar
| first line in baz
| second line in baz
| (echo bar.txt && echo baz.txt) | lines "ISO-8859-1"
| first line in bar
| second line in bar
| first line in baz
| second line in baz
""".stripMargin)
exit
}
}
import scala.io._
val lines = Source.stdin.getLines
for {
file <- lines
line <- Source.fromFile(file, enc).getLines
} println(line)