correct echo utility etc.
This commit is contained in:
parent
2f6f90dce4
commit
5de50196ea
7 changed files with 19 additions and 10 deletions
11
head.nim
11
head.nim
|
|
@ -5,16 +5,17 @@ proc main(files:seq[string], lines=10, bytes=0) =
|
|||
# if files.len == 0:
|
||||
# files.add "-"
|
||||
for file in files:
|
||||
var s = newFileStream(file, fmRead)
|
||||
var f = if file == "-": stdin
|
||||
else: open(file, fmRead)
|
||||
if bytes > 0:
|
||||
var currentByte = 0
|
||||
while not s.atEnd and currentByte < bytes:
|
||||
write(stdout, s.readChar)
|
||||
while not f.endOfFile and currentByte < bytes:
|
||||
write(stdout, f.readChar)
|
||||
inc currentByte
|
||||
elif lines > 0:
|
||||
var currentLine = 0
|
||||
while not s.atEnd and currentLine < lines:
|
||||
echo s.readLine
|
||||
while not f.endOfFile and currentLine < lines:
|
||||
writeLine(stdout, f.readLine)
|
||||
inc currentLine
|
||||
|
||||
dispatch(main, version=("version", nimbaseVersion))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue