From 3383e76ac5286c4ae9dca23b9a91334f912953d6 Mon Sep 17 00:00:00 2001 From: Aida Eslami Date: Mon, 1 Dec 2025 13:32:47 +0000 Subject: [PATCH 1/4] My Cat in Python --- implement-shell-tools/cat/cat.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 implement-shell-tools/cat/cat.py diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py new file mode 100644 index 00000000..49cd1e39 --- /dev/null +++ b/implement-shell-tools/cat/cat.py @@ -0,0 +1,30 @@ +import argparse +parser = argparse.ArgumentParser( + prog="count-containing-words", + description="Counts words in a file that contain a particular character", +) + +counterNumber = 1 +parser.add_argument("-n", action="store_true", help="number all lines") +parser.add_argument("-b", action="store_true", help="The character to search for" ) +parser.add_argument("path", nargs="+", help="The file to search") + +args = parser.parse_args() + +for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + arrText = content.split("\n") + + if args.b: + for i in range(len(arrText )): + if arrText[i].strip() != "": + print(counterNumber,arrText[i]) + counterNumber += 1 + + elif args.n: + for i in range(len(arrText )): + print(counterNumber, arrText[i]) + counterNumber += 1 + else: + print(content) \ No newline at end of file From 7ba19f8079b1b0f20ebfcf6842903cc8b39369bb Mon Sep 17 00:00:00 2001 From: Aida Eslami Date: Mon, 1 Dec 2025 13:34:47 +0000 Subject: [PATCH 2/4] change Cat description and create ls.py file --- implement-shell-tools/cat/cat.py | 4 ++-- implement-shell-tools/ls/ls.py | 0 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 implement-shell-tools/ls/ls.py diff --git a/implement-shell-tools/cat/cat.py b/implement-shell-tools/cat/cat.py index 49cd1e39..98b8b753 100644 --- a/implement-shell-tools/cat/cat.py +++ b/implement-shell-tools/cat/cat.py @@ -1,7 +1,7 @@ import argparse parser = argparse.ArgumentParser( - prog="count-containing-words", - description="Counts words in a file that contain a particular character", + prog="my-cat", + description="Simple cat clone with -n and -b options", ) counterNumber = 1 diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py new file mode 100644 index 00000000..e69de29b From 419f1dbae86d69f227736b0e94f090eb668512ea Mon Sep 17 00:00:00 2001 From: Aida Eslami Date: Mon, 1 Dec 2025 14:27:01 +0000 Subject: [PATCH 3/4] MyLs in python --- implement-shell-tools/ls/ls.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/implement-shell-tools/ls/ls.py b/implement-shell-tools/ls/ls.py index e69de29b..b5a9c9ab 100644 --- a/implement-shell-tools/ls/ls.py +++ b/implement-shell-tools/ls/ls.py @@ -0,0 +1,39 @@ +import argparse +import os + +def show_unhidden_files(listDir): + for file in listDir: + if not file.startswith('.'): + print(file) +def show_all_files(listDir): + for file in listDir: + print(file) + + +parser = argparse.ArgumentParser( + prog="my-ls", + description="Simple ls clone with -a and -l options", +) + +parser.add_argument("-a", action="store_true", help="include hidden files") +parser.add_argument("-1", dest="one" ,action="store_true", help="use a long listing format") +parser.add_argument("path", nargs="?", default=".", help="The directory to list") +args = parser.parse_args() + + + + + +fn = args.path +listDir = os.listdir(fn) +if fn!="": + if args.a and args.one: + show_all_files(listDir) + elif args.a: + show_all_files(listDir) + elif args.one: + show_unhidden_files(listDir) + + else: + show_unhidden_files(listDir) + From 37dc584f13cb624d80d35438074cee6868154e60 Mon Sep 17 00:00:00 2001 From: Aida Eslami Date: Mon, 1 Dec 2025 17:02:02 +0000 Subject: [PATCH 4/4] MyWc in Python --- implement-shell-tools/wc/wc.py | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 implement-shell-tools/wc/wc.py diff --git a/implement-shell-tools/wc/wc.py b/implement-shell-tools/wc/wc.py new file mode 100644 index 00000000..8e139ddc --- /dev/null +++ b/implement-shell-tools/wc/wc.py @@ -0,0 +1,66 @@ +import argparse +parser = argparse.ArgumentParser( + prog="my-wc", + description="Simple wc clone with -l and -w options", +) +lineCounter = 0 +wordCounter = 0 +charCounter = 0 +parser.add_argument("-l", action="store_true", help="count lines") +parser.add_argument("-w", action="store_true", help="count words") +parser.add_argument("-c", action="store_true", help="count characters") +parser.add_argument("path", nargs="+", default=".", help="The file to count") +args = parser.parse_args() + +if not args.l and not args.w and not args.c: + for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + arrText = content.split("\n") + lineCounter += len(arrText) + arrWords = content.split() + wordCounter += len(arrWords) + charCounter += len(content) + print("Line count:", lineCounter,"lines") + print("Word count:", wordCounter,"words") + print("Character count:", charCounter,"characters") +elif args.l and args.w: + for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + arrText = content.split("\n") + lineCounter += len(arrText) + arrWords = content.split() + wordCounter += len(arrWords) + print("Line count:", lineCounter,"lines") + print("Word count:", wordCounter,"words") +elif args.l and args.c: + for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + arrText = content.split("\n") + lineCounter += len(arrText) + charCounter += len(content) + print("Line count:", lineCounter,"lines") + print("Character count:", charCounter,"characters") +elif args.l: + for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + arrText = content.split("\n") + lineCounter += len(arrText) + print("Line count:", lineCounter,"lines") + +elif args.w: + for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + arrText = content.split() + wordCounter += len(arrText) + print("Word count:", wordCounter,"words") +elif args.c: + for file_path in args.path: + with open(file_path, "r") as f: + content = f.read() + charCounter += len(content) + print("Character count:", charCounter,"characters") \ No newline at end of file