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 296d98a commit a25b21eCopy full SHA for a25b21e
1 file changed
implement-shell-tools/cat/cat.js
@@ -1,8 +1,19 @@
1
const fs = require("fs");
2
3
-const files = process.argv.slice(2);
+const args = process.argv.slice(2);
4
5
-for (const file of files) {
6
- const content = fs.readFileSync(file, "utf8");
+const numberLines = args[0] === "-n";
+
7
+const filename = numberLines ? args[1] : args[0];
8
9
+const content = fs.readFileSync(filename, "utf8");
10
11
+const lines = content.split("\n");
12
13
+if (numberLines) {
14
+ lines.forEach((line, index) => {
15
+ console.log(`${String(index + 1).padStart(6)}\t${line}`);
16
+ });
17
+} else {
18
process.stdout.write(content);
19
}
0 commit comments