We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0a3e5a5 commit 10353a9Copy full SHA for 10353a9
1 file changed
implement-shell-tools/cat/cat.js
@@ -1,4 +1,35 @@
1
-const fs = require ("fs");
+const fs = require("fs");
2
+
3
const args = process.argv.slice(2);
-const content = fs.readFileSync(args[0], "utf-8")
4
-console.log(content);
5
+let mode = "normal";
6
7
+if (args[0] === "-b") {
8
+ mode = "numberNonEmpty";
9
+}
10
11
+const files = args.slice(1);
12
13
+let lineNum = 1;
14
15
+for (const file of files) {
16
17
+ const content = fs.readFileSync(file, "utf8");
18
19
+ const lines = content.trimEnd().split("\n");
20
21
+ for (const line of lines) {
22
23
+ if (mode === "numberNonEmpty") {
24
25
+ if (line !== "") {
26
+ console.log(lineNum + " " + line);
27
+ lineNum++;
28
+ } else {
29
+ console.log(line);
30
+ }
31
32
33
34
35
0 commit comments