Closes #4
This commit is contained in:
Samuel Sloniker 2022-12-01 11:59:41 -08:00
parent 4b25f8f2bd
commit 9757d2c18d
Signed by: kj7rrv
GPG Key ID: 1BB4029E66285A62

25
bin/grep.py Normal file
View File

@ -0,0 +1,25 @@
import os
import re
import console
def get_app_class(template):
class App(template):
def F_main(self):
pattern = self.argv[1].encode("utf-8")
file = self.argv[2]
try:
with open(file, "rb") as f:
for line in f.readlines():
if re.search(pattern, line):
self.console.write(line)
except OSError as e:
try:
os.listdir(file)
console.write_str(self.console, f"grep: {file}: Is a directory\n")
except OSError:
console.write_str(self.console, f"grep: {file}: No such file or directory\n")
self.exit()
return App