This challenge corresponds to the 21st part of the Coding Challenges series by John Crickett https://codingchallenges.fyi/challenges/challenge-sed.
The Sed tool is written in sed.ts
. The tool is used to perform basic text transformations on an input stream (a file or input from stdin).
You can use ts-node
to run the tool as follows:
# Substitute <this> for <that> everywhere <this> appears in the file <filename>
npx ts-node sed.ts s/<this>/<that>/g <filename>
# Print lines 2 to 4 from file <filename>
npx ts-node sed.ts -n "2,4p" <filename>
# Output only lines containing a specific pattern <pattern> from file <filename>
npx ts-node sed.ts -n /pattern/p <filename>
# Add another line after each line, i.e. double spacing a file.
npx ts-node sed.ts G <filename>
# Edit in-place: Substitute <this> for <that> everywhere <this> appears in the file <filename>
npx ts-node sed.ts -i 's/<this>/<that>/g' <filename>
The following options are supported:
- Character replacement
- Range of lines selection
- Output only lines containing a specific pattern
- Double spacing a file using option
- Strip trailing blank lines from a file
- Edit in-place
To use the tool in stdin mode, use the following command:
cat filename | npx ts-node sed.ts [option]
To run the tests for the Sed tool, go to the root directory of this repository and run the following command:
npm test src/21/