File tree Expand file tree Collapse file tree
implement-shell-tools/cat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const folderPath = "./sample-files" ;
3+ const content = fs . readdirSync ( folderPath ) ;
4+
5+ const txtFiles = content . filter ( ( file ) => file . endsWith ( ".txt" ) ) ;
6+ process . stdout . write ( txtFiles . join ( "\n" ) ) ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const filePath = "./sample-files/3.txt" ;
3+ const content = fs . readFileSync ( filePath , "utf-8" ) ;
4+
5+ let count = 1 ;
6+ const numberLines = content . split ( "\n" ) . map ( ( line ) => {
7+ if ( line . trim ( ) !== "" ) {
8+ return `${ count ++ } ${ line . trim ( ) } ` ;
9+ }
10+ return "" ;
11+ } ) ;
12+ process . stdout . write ( numberLines . join ( "\n" ) ) ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const folderPath = "./sample-files" ;
3+ const content = fs . readdirSync ( folderPath ) ;
4+
5+ const txtFiles = content . filter ( ( file ) => file . endsWith ( ".txt" ) ) ;
6+ const numberedLine = txtFiles . map ( ( line , index ) => {
7+ return `${ index + 1 } ${ line } ` ;
8+ } ) ;
9+ process . stdout . write ( numberedLine . join ( "\n" ) ) ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const filePath = "./sample-files/1.txt" ;
3+ const content = fs . readFileSync ( filePath , "utf-8" ) ;
4+
5+ const lineNumber = content . split ( "\n" ) . map ( ( line , index ) => {
6+ return `${ index + 1 } ${ line } ` ;
7+ } ) ;
8+ process . stdout . write ( lineNumber . join ( "\n" ) ) ;
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const filePath = "./sample-files/1.txt" ;
3+
4+ const content = fs . readFileSync ( filePath , "utf-8" ) ;
5+
6+ process . stdout . write ( content ) ;
You can’t perform that action at this time.
0 commit comments