read-write-edit-tools 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: read-write-edit-tools
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Fast hex-line-numbered file read, write, and edit CLI
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Homepage, https://github.com/llaa33219/read-write-edit-tools
@@ -33,16 +33,17 @@ The tool deliberately has a narrow scope:
33
33
  - `read` displays text with stable, 1-based hexadecimal line addresses.
34
34
  - `write` creates a new file and **refuses to overwrite anything that already
35
35
  exists**.
36
- - `edit` replaces one or more lines, including multiple lines in one block,
37
- using addresses from the **original file**.
36
+ - `edit` replaces original lines with whole replacement blocks, or deletes
37
+ them, after verifying each addressed line's exact current content.
38
38
 
39
39
  It is not a general-purpose editor, binary-file tool, search tool, merge tool,
40
- or interactive terminal UI. It does not delete lines or files, append to
41
- files, create parent directories, or provide pattern-based substitution.
40
+ or interactive terminal UI. It does not delete files, append to files,
41
+ create parent directories, or provide pattern-based substitution.
42
42
 
43
43
  > **The essential `edit` rule:** every address in one `edit` command refers to
44
- > the file as it existed **before that command started**. If one replacement
45
- > adds or removes lines, that does not change any other address in the same
44
+ > the file as it existed **before that command started**. Each pair's
45
+ > replacement is one whole block inserted at that pair's lowest addressed
46
+ > position, so its size does not change any other address in the same
46
47
  > command. The complete example below shows this explicitly.
47
48
 
48
49
  ## Contents
@@ -165,9 +166,9 @@ create or modify their target files exactly as documented:
165
166
  uvx --from read-write-edit-tools rwe write ephemeral-demo.txt 'First line
166
167
  Second line'
167
168
 
168
- uvx --from read-write-edit-tools rwe edit ephemeral-demo.txt '01: Replacement for original line 01
169
- An additional line
170
- 02: Replacement for original line 02'
169
+ uvx --from read-write-edit-tools rwe edit ephemeral-demo.txt '01: First line
170
+ 02: Second line' 'Replacement for original line 01
171
+ An additional line'
171
172
 
172
173
  uvx --from read-write-edit-tools rwe read ephemeral-demo.txt
173
174
  ```
@@ -243,7 +244,7 @@ development.
243
244
  ```text
244
245
  rwe read FILE [RANGE]
245
246
  rwe write FILE CONTENT
246
- rwe edit FILE EDITS
247
+ rwe edit FILE OLD NEW [OLD NEW ...]
247
248
  ```
248
249
 
249
250
  | Command | Purpose | Modifies a file? |
@@ -251,7 +252,7 @@ rwe edit FILE EDITS
251
252
  | `rwe read FILE` | Print up to 1000 lines with hexadecimal addresses | No |
252
253
  | `rwe read FILE RANGE` | Print a single line or inclusive range | No |
253
254
  | `rwe write FILE CONTENT` | Create a file containing exactly `CONTENT` | Yes, only if `FILE` does not exist |
254
- | `rwe edit FILE EDITS` | Replace addressed lines from the original file | Yes |
255
+ | `rwe edit FILE OLD NEW [OLD NEW ...]` | Replace addressed lines from the original file | Yes |
255
256
  | `rwe --help` or `rwe -h` | Print a short command reference | No |
256
257
  | `rwe --version` or `rwe -V` | Print the version | No |
257
258
 
@@ -264,11 +265,13 @@ rwe edit FILE EDITS
264
265
  | `FILE` | Path to the file to read, create, or edit |
265
266
  | `RANGE` | One hexadecimal address, or `START:END`; see below |
266
267
  | `CONTENT` | The complete new file content as **one shell argument** |
267
- | `EDITS` | One or more edit blocks as **one shell argument** |
268
+ | `OLD` | Original lines to replace: `HEX: content` lines copied from `read` |
269
+ | `NEW` | The replacement lines as **one shell argument**; `''` deletes the addressed lines |
268
270
 
269
- For `write` and `edit`, a final argument of exactly `-` reads `CONTENT` or
270
- `EDITS` from standard input. `read FILE -` is **not** standard-input syntax;
271
- for `read`, `-` is interpreted as a range and is invalid.
271
+ For `write`, a final argument of exactly `-` reads `CONTENT` from standard
272
+ input. For `edit`, at most one argument among all the `OLD` and `NEW`
273
+ arguments may be `-`. `read FILE -` is **not** standard-input syntax; for
274
+ `read`, `-` is interpreted as a range and is invalid.
272
275
 
273
276
  ### Quick examples
274
277
 
@@ -285,14 +288,18 @@ rwe read notes.txt
285
288
  rwe read notes.txt 03
286
289
  rwe read notes.txt 01:03
287
290
 
288
- # Replace original lines 01 and 03 in one operation.
289
- rwe edit notes.txt '01: New first line
290
- 03: New third line'
291
+ # Replace original lines 01 and 02 in one operation.
292
+ rwe edit notes.txt '01: First line
293
+ 02: Second line' 'New first line
294
+ New second line'
291
295
 
292
296
  # Replace original line 02 with two lines.
293
- rwe edit notes.txt '02: Replacement line
297
+ rwe edit notes.txt '02: Second line' 'Replacement line
294
298
  An additional line'
295
299
 
300
+ # Replace original lines 01 and 03 as two regions; line 02 stays in place.
301
+ rwe edit notes.txt '01: First line' 'New first line' '03: Third line' 'New third line'
302
+
296
303
  # Re-read after every edit to obtain the new addresses.
297
304
  rwe read notes.txt
298
305
  ```
@@ -318,7 +325,7 @@ Addresses are hexadecimal (`0`–`9`, `a`–`f`), and the first line is `01`, no
318
325
 
319
326
  Output uses lowercase hexadecimal. Input accepts lowercase or uppercase, so
320
327
  `b7` and `B7` refer to the same line. Leading zeros are allowed on input:
321
- `1`, `01`, and `001` all address line 1. In one `edit` argument, using more
328
+ `1`, `01`, and `001` all address line 1. In one `OLD` argument, using more
322
329
  than one spelling of the same address is a duplicate-address error.
323
330
 
324
331
  `00` is always invalid, including `000` and other all-zero forms.
@@ -379,7 +386,7 @@ Put `--` immediately after the subcommand:
379
386
  ```sh
380
387
  rwe read -- -notes.txt
381
388
  rwe write -- -new.txt 'content'
382
- rwe edit -- -notes.txt '01: replacement'
389
+ rwe edit -- -notes.txt '01: - line one' '0a: - line ten'
383
390
  ```
384
391
 
385
392
  Paths containing spaces follow normal shell quoting rules:
@@ -390,9 +397,9 @@ rwe read 'my notes.txt'
390
397
 
391
398
  ## Complete workflow
392
399
 
393
- This example demonstrates the most easily misunderstood behavior: original
394
- addresses remain fixed throughout one `edit`, even when a replacement expands
395
- to multiple lines.
400
+ This example demonstrates the most easily misunderstood behaviors: original
401
+ addresses remain fixed throughout one `edit`, and the replacement is one
402
+ whole block whose size can differ from the number of addressed lines.
396
403
 
397
404
  ### 1. Create the original file
398
405
 
@@ -419,16 +426,23 @@ Output:
419
426
  ### 3. Expand line 01 and replace line 03 in the same command
420
427
 
421
428
  ```sh
422
- rwe edit example.txt '01: New first line
429
+ rwe edit example.txt '01: First line
430
+ 02: Second line
431
+ 03: Third line' 'New first line
423
432
  Inserted second line
424
- 03: New third line'
433
+ Second line
434
+ New third line'
425
435
  ```
426
436
 
427
- The edit argument has two blocks:
437
+ The command addresses all three original lines at once. `OLD` holds the
438
+ verified original content copied from the `read` output above, and `NEW`
439
+ holds the whole replacement block:
428
440
 
429
- 1. Replace **original line `01`** with two lines: `New first line` and
430
- `Inserted second line`.
431
- 2. Replace **original line `03`** (`Third line`) with `New third line`.
441
+ 1. `First line` becomes `New first line`, followed by a new `Inserted second
442
+ line`.
443
+ 2. `Second line` is kept as `Second line`; addressing a line is not a promise
444
+ to change it, and the guard would have rejected a mistyped copy.
445
+ 3. `Third line` becomes `New third line`.
432
446
 
433
447
  ### 4. Read the result
434
448
 
@@ -439,31 +453,31 @@ The edit argument has two blocks:
439
453
  04: New third line
440
454
  ```
441
455
 
442
- Address `03` in the command did **not** mean “line 3 after inserting a line.”
443
- It still meant original `Third line`. Original `Second line` was not edited,
444
- so it moved from line `02` to line `03` in the result. The replacement for
445
- original line `03` consequently appears at line `04`.
456
+ Original `Second line` was re-supplied unchanged in `NEW`, so it moved from
457
+ line `02` to line `03` in the result.
446
458
 
447
- Internally, `rwe` validates all addresses against the original file and applies
448
- replacements from bottom to top. The practical consequences are:
459
+ Internally, `rwe` validates all addresses and all content matches against
460
+ the original file, removes the addressed lines, and inserts `NEW` at the
461
+ lowest addressed position. The practical consequences are:
449
462
 
450
463
  - Every address in one call uses the same original snapshot.
451
- - Blocks may be written in ascending, descending, or mixed address order.
452
- - A replacement with multiple lines never shifts later addresses in that
453
- same call.
464
+ - `OLD` lines may be written in ascending, descending, or mixed address
465
+ order; the result is the same.
466
+ - The size of `NEW` never shifts any other address in that same call.
454
467
  - You cannot address a newly inserted line elsewhere in the same call.
455
468
  - Addresses are not persistent IDs. After the command finishes, run `read`
456
469
  again and use its addresses for the next `edit`.
457
470
 
458
- For example, the following two-block edit is also valid and has the same
459
- addressing semantics:
471
+ For example, the following edit is also valid and has the same addressing
472
+ semantics:
460
473
 
461
474
  ```sh
462
- rwe edit example.txt '04: Replacement for current original line 04
463
- 01: Replacement for current original line 01'
475
+ rwe edit example.txt '02: Inserted second line
476
+ 01: New first line' 'Replacement for current original line 02
477
+ Replacement for current original line 01'
464
478
  ```
465
479
 
466
- Here `04` and `01` refer to the result shown immediately above, because this
480
+ Here `02` and `01` refer to the result shown immediately above, because this
467
481
  is a new invocation with a new original snapshot.
468
482
 
469
483
  ## `read`: display numbered content
@@ -677,238 +691,390 @@ The byte count is the encoded content length, not a character count.
677
691
  ### Basic form
678
692
 
679
693
  ```sh
680
- rwe edit FILE EDITS
694
+ rwe edit FILE OLD NEW [OLD NEW ...]
681
695
  ```
682
696
 
683
- `EDITS` is one argument containing one or more blocks. Each block starts at
684
- the beginning of a line:
697
+ `OLD` names the original lines to replace. Each of its lines is copied from
698
+ `rwe read` output:
685
699
 
686
700
  ```text
687
- HEX_ADDRESS: replacement content
701
+ HEX_ADDRESS: original content
688
702
  ```
689
703
 
690
- For example:
704
+ `NEW` is the replacement: plain lines with no prefixes, passed as **one
705
+ argument**. For example, given:
691
706
 
692
- ```sh
693
- rwe edit notes.txt '01: Replacement for original line 01
694
- 02: Replacement for original line 02'
707
+ ```text
708
+ 01: First line
709
+ 02: Second line
710
+ 03: Third line
695
711
  ```
696
712
 
697
- Each block replaces exactly one original line. Its replacement may itself
698
- contain zero characters, one line, or multiple lines.
699
-
700
- ### Multiple blocks and multiline replacements
713
+ this command replaces original line 2:
701
714
 
702
715
  ```sh
703
- rwe edit notes.txt '01: First replacement line
704
- Second line in the replacement for original 01
716
+ rwe edit notes.txt '02: Second line' 'Replacement for original line 02'
717
+ ```
718
+
719
+ The result is:
720
+
721
+ ```text
722
+ 01: First line
705
723
  02: Replacement for original line 02
706
- b7: Replacement for original line b7'
724
+ 03: Third line
707
725
  ```
708
726
 
709
- This command addresses three original lines:
727
+ Every `edit` therefore starts from `read` output: copy the lines being
728
+ changed into `OLD`, then write the replacement in `NEW`.
710
729
 
711
- - Original `01` becomes two lines.
712
- - Original `02` becomes one line.
713
- - Original `b7` becomes one line.
730
+ ### The mis-edit guard
714
731
 
715
- The second and third addresses are still interpreted against the original
716
- file; the expansion at `01` does not move them.
732
+ The content after the colon in `OLD` must **exactly match** the current line
733
+ in the file. If any addressed line differs, the whole command is rejected and
734
+ the file is left unchanged. A stale address or a typo produces:
717
735
 
718
- ### Original-address rules
736
+ ```text
737
+ rwe: line 1 does not match the given original content; file left unchanged (expected 'Frist line', found 'First line')
738
+ ```
739
+
740
+ The guard compares the full line, byte for byte, so copying `OLD` from an old
741
+ `read`, or from memory, fails safely instead of editing the wrong line. Copy
742
+ `OLD` lines from a fresh `rwe read` of the file being edited.
719
743
 
720
- 1. Read the file to obtain current addresses.
721
- 2. Build one or more replacement blocks using those addresses.
722
- 3. Pass all blocks in one `edit` invocation.
723
- 4. `rwe` validates every block before saving anything.
724
- 5. Replacements are applied from the highest original address to the lowest.
725
- 6. Read the resulting file before planning another edit.
744
+ ### Whole-block replacement
726
745
 
727
- Block order in `EDITS` does not determine application order. These are
728
- semantically equivalent:
746
+ All addressed original lines are removed, and `NEW` is inserted as one block
747
+ at the **lowest** addressed position. The number of replacement lines is
748
+ free; it need not match the number of addresses.
749
+
750
+ Shrinking, three original lines replaced by two:
729
751
 
730
752
  ```text
731
- 01: First
732
- 03: Third
753
+ 01: one
754
+ 02: two
755
+ 03: three
756
+ ```
757
+
758
+ ```sh
759
+ rwe edit notes.txt '01: one
760
+ 02: two
761
+ 03: three' 'first
762
+ second'
733
763
  ```
734
764
 
765
+ Result:
766
+
735
767
  ```text
736
- 03: Third
737
- 01: First
768
+ 01: first
769
+ 02: second
738
770
  ```
739
771
 
740
- Both replace original lines 1 and 3. Duplicate addresses are never merged or
741
- applied sequentially.
772
+ Growing, two original lines replaced by five:
742
773
 
743
- ### What `edit` does not do
774
+ ```sh
775
+ rwe edit notes.txt '01: x
776
+ 02: y' 'p
777
+ q
778
+ r
779
+ s
780
+ t'
781
+ ```
744
782
 
745
- - `02:` makes original line 2 **empty**; it does not delete the line.
746
- - A multiline replacement expands a line; there is no separate insertion-only
747
- operation.
748
- - There is no “current line 3 after previous block” addressing mode.
749
- - There is no range replacement syntax such as `01:03: text`. The first colon
750
- ends the address, so that form is content for address `01`, not a range.
751
- - There is no regular-expression or search-and-replace mode.
752
- - An empty file has no addressable lines, so it cannot be populated with
753
- `edit`; remove it and use `write` instead.
783
+ Result:
784
+
785
+ ```text
786
+ 01: p
787
+ 02: q
788
+ 03: r
789
+ 04: s
790
+ 05: t
791
+ ```
754
792
 
755
- ### Header recognition
793
+ Deleting, with `NEW` as the empty string, removes the addressed lines
794
+ entirely. Given `a`, `b`, `c`:
756
795
 
757
- A new block starts only when a line begins with one or more hexadecimal digits
758
- immediately followed by `:`. Examples recognized as headers:
796
+ ```sh
797
+ rwe edit notes.txt '02: b' ''
798
+ ```
799
+
800
+ Result:
759
801
 
760
802
  ```text
761
- 1: content
762
- 01: content
763
- B7: content
764
- dead: content
803
+ 01: a
804
+ 02: c
765
805
  ```
766
806
 
767
- The address need not have the same width shown by `read`. `1` and `01` both
768
- mean original line 1.
807
+ ### Non-contiguous addresses
769
808
 
770
- These continuation lines are **not** headers:
809
+ Addresses need not be adjacent, and separated regions can stay separated.
810
+ Given:
771
811
 
772
812
  ```text
773
- 02: indented, so this is content
774
- not-hex: content
775
- http://example.com
776
- 3.14: content
813
+ 01: a
814
+ 02: b
815
+ 03: c
777
816
  ```
778
817
 
779
- Because only the beginning of a line can start a header, a colon elsewhere in
780
- normal content has no special meaning.
818
+ this command replaces original lines 1 and 3 as two independent regions and
819
+ leaves line 2 untouched in place:
781
820
 
782
- Non-whitespace content before the first recognized header is an error. Leading
783
- blank or whitespace-only lines before the first block are ignored.
821
+ ```sh
822
+ rwe edit notes.txt '01: a' 'x' '03: c' 'y'
823
+ ```
784
824
 
785
- ### Spaces and tabs after the colon
825
+ The result is:
786
826
 
787
- One ASCII space or one tab immediately after the colon is treated as a
788
- separator and removed. It is optional:
827
+ ```text
828
+ 01: x
829
+ 02: b
830
+ 03: y
831
+ ```
832
+
833
+ Each pair replaces one region on its own: its `OLD` lines are removed and
834
+ its `NEW` is inserted at that pair's lowest address. The middle line is not
835
+ addressed, so it stays in place. With `NEW` as `''` for both pairs instead,
836
+ both addressed lines are removed and only `b` remains:
789
837
 
790
838
  ```text
791
- 01: Replacement # Replacement content is "Replacement"
792
- 01:Replacement # Replacement content is "Replacement"
839
+ 01: b
793
840
  ```
794
841
 
795
- If there are multiple spaces, only the first is removed:
842
+ Non-contiguous addresses in one `OLD` are rejected. The lines in a single
843
+ `OLD` must form one contiguous run, for example `'01: a\n02: b'` but not
844
+ `'01: a\n03: c'`; split separated regions into `OLD` `NEW` pairs instead,
845
+ one pair per region, and each region stays separate.
846
+
847
+ ### Several regions in one command
848
+
849
+ Each pair replaces one region on its own, so two separated regions can be
850
+ replaced in one command instead of two invocations. Given:
796
851
 
797
852
  ```text
798
- 01: indented
853
+ 01: a
854
+ 02: b
855
+ 03: c
856
+ 04: d
857
+ 05: e
858
+ 06: f
799
859
  ```
800
860
 
801
- produces content beginning with two spaces.
861
+ the first pair replaces `01`-`02` with `X`, the second replaces `05`-`06`
862
+ with `Y`, and untouched lines `03`-`04` stay in place:
802
863
 
803
- On continuation lines, indentation and other whitespace are preserved exactly
804
- as supplied in the edit argument.
864
+ ```sh
865
+ rwe edit notes.txt '01: a
866
+ 02: b' 'X' '05: e
867
+ 06: f' 'Y'
868
+ ```
805
869
 
806
- ### Empty replacements and blank lines
870
+ Result:
807
871
 
808
- Given an original file:
872
+ ```text
873
+ 01: X
874
+ 02: c
875
+ 03: d
876
+ 04: Y
877
+ ```
878
+
879
+ The regions may sit anywhere in the file, and each pair's `NEW` has its
880
+ own size. Given:
809
881
 
810
882
  ```text
811
- 01: A
812
- 02: B
813
- 03: C
814
- 04: D
883
+ 01: a
884
+ 02: b
885
+ 03: keep1
886
+ 04: keep2
887
+ 05: c
888
+ 06: d
889
+ 07: f
815
890
  ```
816
891
 
817
- this command:
892
+ this command replaces `01`-`02` with `대체` and `05`-`07` with `대체2`:
818
893
 
819
894
  ```sh
820
- rwe edit notes.txt '01:
821
- 03: Replacement
895
+ rwe edit f.txt '01: a
896
+ 02: b' '대체' '05: c
897
+ 06: d
898
+ 07: f' '대체2'
899
+ ```
900
+
901
+ Result:
902
+
903
+ ```text
904
+ 01: 대체
905
+ 02: keep1
906
+ 03: keep2
907
+ 04: 대체2
908
+ ```
909
+
910
+ All pairs use the same original snapshot, and pair order is irrelevant:
911
+ swapping the two pairs above produces the same result. The pairs may also
912
+ interleave, for example one pair addressing `01` and `05` while another
913
+ addresses `03`.
914
+
915
+ ### `NEW` terminator semantics
916
+
917
+ `NEW` is one argument holding plain replacement lines. One final newline at
918
+ the end of the argument is a terminator, not an extra line:
822
919
 
920
+ - `NEW` `''`, the empty string, deletes the addressed lines.
921
+ - `NEW` holding one newline character leaves **one blank line**.
922
+ - `NEW` holding two newline characters leaves **two blank lines**.
923
+ - In shell single quotes, `'x` NEWLINE `y'` and `'x` NEWLINE `y` NEWLINE `'`
924
+ both produce the two lines `x` and `y`.
925
+
926
+ These are byte-exact: one blank line means one LF, not zero and not two. In a
927
+ shell, a newline character inside single quotes is written by ending the line
928
+ inside the quoted argument, so this leaves exactly one blank line where `a`
929
+ was:
930
+
931
+ ```sh
932
+ rwe edit notes.txt '01: a' '
823
933
  '
824
934
  ```
825
935
 
826
- has the following meaning:
936
+ An empty replacement **line** is therefore different from an empty
937
+ replacement: blank `NEW` lines leave empty lines in the file, while `NEW` `''`
938
+ removes the addressed lines. Emptying every line of a file this way still
939
+ leaves one blank line per address, so the file never reaches 0 bytes; to
940
+ truly empty it, address every line with `NEW` `''`, or remove the file and
941
+ recreate it with `write ''`.
827
942
 
828
- - Original `01` becomes an empty line.
829
- - Original `03` becomes `Replacement` followed by an empty line.
943
+ ### Original-address rules
830
944
 
831
- The result is:
945
+ 1. Read the file to obtain current addresses and exact line content.
946
+ 2. Copy every line you intend to replace into `OLD`.
947
+ 3. Write the complete replacement in `NEW`, all in one argument.
948
+ 4. `rwe` validates every address and every content match before saving
949
+ anything.
950
+ 5. Re-read the resulting file before planning another edit.
951
+
952
+ All addresses refer to the file as it existed **before the command started**.
953
+ `OLD` line order is irrelevant; these two `OLD` arguments are equivalent:
832
954
 
833
955
  ```text
834
- 01:
835
- 02: B
836
- 03: Replacement
837
- 04:
838
- 05: D
956
+ 01: First
957
+ 02: Second
839
958
  ```
840
959
 
841
- To understand blank lines, remember these parser rules:
960
+ ```text
961
+ 02: Second
962
+ 01: First
963
+ ```
842
964
 
843
- - The newline before the next header terminates the previous block; it is not
844
- an additional content line.
845
- - One newline at the very end of the `EDITS` argument is treated as the final
846
- block terminator.
847
- - Extra newlines beyond those terminators become blank replacement lines.
848
- - To make the last block end in a blank line, include an extra blank line
849
- before the closing shell quote.
965
+ Both address original lines 1 and 2, and in both cases the result is the
966
+ same. Because the whole block is replaced at once, the size of `NEW` cannot
967
+ shift any other address in the same command. Addresses are not persistent
968
+ IDs: after the command finishes, run `read` again and use its addresses for
969
+ the next `edit`.
850
970
 
851
- ### Escaping a content line that looks like a header
971
+ ### What `edit` does not do
972
+
973
+ - There is no range syntax. `OLD` names individual lines, one per header;
974
+ `01:03` is not a range. To replace a run of lines, address each of them.
975
+ - There is no regular-expression or search-and-replace mode. `OLD` content is
976
+ compared literally, byte for byte.
977
+ - Deletion is supported only through `NEW` `''`; there is no separate delete
978
+ header or delete-only form.
979
+ - There is no "current line 3 after the previous replacement" addressing
980
+ mode.
981
+ - An empty file has no addressable lines, so it cannot be populated with
982
+ `edit`; remove it and use `write` instead.
983
+
984
+ ### `OLD` line format
852
985
 
853
- Suppose original line `01` should become:
986
+ Every line of `OLD` must be a header:
854
987
 
855
988
  ```text
856
- First replacement line
857
- dead: This must remain literal content
989
+ 1: content
990
+ 01: content
991
+ B7: content
992
+ dead: content
858
993
  ```
859
994
 
860
- Because `dead` is valid hexadecimal, an unescaped continuation line beginning
861
- `dead:` would start a new block. Prefix it with one backslash:
995
+ There are no continuation lines in `OLD`: each line addresses exactly one
996
+ original line, and no escaping is ever needed, because replacement text lives
997
+ in `NEW`. A plain line without an address, or a blank line, is rejected:
862
998
 
863
- ```sh
864
- rwe edit notes.txt '01: First replacement line
865
- \dead: This must remain literal content
866
- 02: Replacement for original line 02'
999
+ ```text
1000
+ expected 'HEX: original content', got: 'plain line'
867
1001
  ```
868
1002
 
869
- On continuation lines, a backslash is removed only when the text after it
870
- would otherwise be recognized as an edit header. Other backslashes remain
871
- unchanged. The escape applies to continuation lines, not to the first header
872
- of a block.
1003
+ The address need not use the width shown by `read`; `1` and `01` both address
1004
+ original line 1.
1005
+
1006
+ ### Spaces and tabs after the colon
873
1007
 
874
- In POSIX single quotes the backslash reaches `rwe` literally. When generating
875
- edit strings in another programming language, account for that language's own
876
- backslash escaping as well.
1008
+ One ASCII space or one tab immediately after the colon in `OLD` is treated as
1009
+ a separator and removed. It is optional:
1010
+
1011
+ ```text
1012
+ 01: Second line # original content is "Second line"
1013
+ 01:Second line # original content is "Second line"
1014
+ ```
1015
+
1016
+ If there are multiple spaces, only the first is removed, so `01: indented`
1017
+ names the original line ` indented` (two leading spaces). `read` output
1018
+ always uses exactly one space, so lines copied from `read` need no
1019
+ adjustment.
1020
+
1021
+ In `NEW`, all whitespace is literal content; nothing is stripped.
877
1022
 
878
1023
  ### Edit from standard input
879
1024
 
880
- Use `-` as the entire `EDITS` argument:
1025
+ At most one argument among all the `OLD` and `NEW` arguments may be `-`,
1026
+ read from standard input:
1027
+
1028
+ ```sh
1029
+ rwe edit notes.txt - 'New text' <<'EOF'
1030
+ 01: First line
1031
+ 02: Second line
1032
+ EOF
1033
+ ```
1034
+
1035
+ A quoted here-document `<<'EOF'` passes quotes and backslashes literally,
1036
+ which suits `OLD` lines and quoted code in `NEW`. For content containing
1037
+ single quotes, read `OLD` from standard input and quote `NEW` with double
1038
+ quotes, or the reverse:
881
1039
 
882
1040
  ```sh
883
- rwe edit notes.txt - <<'EOF'
884
- 01: Replacement from standard input
885
- 03: Another original-line replacement
1041
+ rwe edit f.txt - 'x = "new"' <<'EOF'
1042
+ 01: x = 'old'
886
1043
  EOF
887
1044
  ```
888
1045
 
889
- This is useful for generated edit scripts and content containing quotes. The
890
- edit syntax is otherwise identical, including the rule that one final newline
891
- terminates the last block.
1046
+ Here `OLD` comes from the here-document, and `NEW` is the single line
1047
+ `x = "new"`. Passing `-` for more than one argument is an error.
892
1048
 
893
1049
  ### Validation is all-or-nothing before saving
894
1050
 
895
1051
  The file is not intentionally changed if any of these conditions occurs:
896
1052
 
897
- - No valid edit block exists
898
- - Non-whitespace content appears before the first block
899
- - An address is zero or malformed as a header
900
- - An address appears more than once, including aliases such as `1` and `01`
1053
+ - The number of `OLD` and `NEW` arguments is odd, so they do not form pairs
1054
+ (a usage error)
1055
+ - `OLD` is empty or contains no valid header
1056
+ - A line of `OLD` is not of the form `HEX: original content`
1057
+ - An address is zero or not hexadecimal
1058
+ - An address appears more than once, in one `OLD` or across pairs,
1059
+ including aliases such as `1` and `01`
901
1060
  - Any address is beyond the original file's last line
1061
+ - Addresses in one OLD are not contiguous
1062
+ - Any addressed line's content does not exactly match the file, in any pair
1063
+ (the mis-edit guard)
902
1064
  - Any original line is not valid UTF-8
903
- - Standard-input edit data is not valid UTF-8
1065
+ - `OLD` or `NEW` from standard input is not valid UTF-8
904
1066
  - The target is not a regular file after resolving symbolic links
1067
+ - More than one argument is `-` (standard input)
905
1068
 
906
1069
  For example, this rejects the **entire** operation rather than applying the
907
- valid first block:
1070
+ valid first pair:
908
1071
 
909
1072
  ```sh
910
- rwe edit three-lines.txt '01: Valid replacement
911
- ff: Invalid if the file has only three lines'
1073
+ rwe edit three-lines.txt '01: First line' 'Valid replacement' 'ff: Anything' 'X'
1074
+ ```
1075
+
1076
+ ```text
1077
+ rwe: line ff is outside the file (3 lines total)
912
1078
  ```
913
1079
 
914
1080
  On success, `rwe` prints:
@@ -917,8 +1083,23 @@ On success, `rwe` prints:
917
1083
  Edited notes.txt (2 original line addresses)
918
1084
  ```
919
1085
 
920
- The count is the number of distinct original addresses, not the number of
921
- replacement lines.
1086
+ The count is the number of distinct original addresses across all pairs,
1087
+ not the number of replacement lines.
1088
+
1089
+ ### Migrating from 0.1.x
1090
+
1091
+ Version 0.2.0 replaces the single-argument edit form and the `HEX-` delete
1092
+ blocks of 0.1.x:
1093
+
1094
+ - 0.1.x passed one `EDITS` argument whose blocks looked like
1095
+ `01: new content`, and deleted lines with headers such as `02-`.
1096
+ - 0.2.0 passes pairs: `OLD` holds the **verified original lines** copied
1097
+ from `read` (`01: old content`), and `NEW` holds the replacement with no
1098
+ prefixes. Deletion is `NEW` `''`. One pair is the minimum; the same
1099
+ command accepts further `OLD NEW` pairs.
1100
+
1101
+ The old form no longer parses: `rwe edit notes.txt '01: text'` fails with a
1102
+ usage error because `edit` now requires one or more `OLD NEW` pairs.
922
1103
 
923
1104
  ## Input, output, paths, and encoding
924
1105
 
@@ -948,9 +1129,9 @@ needs only another stream's data.
948
1129
  - `read` recognizes LF (`\n`) and strips a preceding CR for CRLF display.
949
1130
  - A lone carriage return is not treated as a line separator in the original
950
1131
  file.
951
- - CRLF and CR characters inside the `EDITS` argument itself are normalized to
952
- LF for parsing; original file line-ending preservation is handled
953
- separately when replacements are rendered.
1132
+ - CRLF and CR characters inside the `OLD` or `NEW` argument are normalized
1133
+ to LF for parsing; original file line-ending preservation is handled
1134
+ separately when the replacement is rendered.
954
1135
  - No character-set auto-detection or encoding option is provided.
955
1136
  - Binary files are unsupported.
956
1137
 
@@ -969,24 +1150,24 @@ symbolic link itself remains a link.
969
1150
  ### What is preserved by `edit`
970
1151
 
971
1152
  - Existing file permission bits are copied to the temporary file.
972
- - Each replaced original line keeps its original LF or CRLF ending.
973
1153
  - Unselected lines retain their original bytes after the whole file has
974
1154
  passed UTF-8 validation.
975
- - A one-line replacement of a final line without a newline remains without a
976
- final newline.
977
- - When a multiline replacement expands an unterminated final line, the last
978
- new line remains unterminated; earlier inserted lines use the file's first
979
- encountered line-ending style, defaulting to LF.
1155
+ - The replacement uses the file's first encountered line-ending style,
1156
+ defaulting to LF. Unselected lines keep their original LF or CRLF endings.
1157
+ - A replacement of a final line without a newline remains without a final
1158
+ newline. When a multiline replacement expands an unterminated final line,
1159
+ the last new line remains unterminated.
980
1160
  - A symbolic link remains a symbolic link while its target is edited.
981
1161
 
982
1162
  ### Atomic save model
983
1163
 
984
1164
  `edit` follows this sequence:
985
1165
 
986
- 1. Parse all edit blocks.
1166
+ 1. Parse the `OLD` addresses and the `NEW` replacement lines.
987
1167
  2. Resolve the target and read the original file.
988
1168
  3. Validate the file type, UTF-8 content, and every address.
989
- 4. Build replacements in memory, from bottom to top.
1169
+ 4. Remove the addressed original lines bottom-up and build the replacement
1170
+ in memory.
990
1171
  5. Create a temporary file in the target's directory.
991
1172
  6. Copy the original permission bits and write the complete result.
992
1173
  7. Replace the target with `os.replace`.
@@ -1010,7 +1191,9 @@ locking, or conflict detection.
1010
1191
  file or parent directory. Atomic replacement is not a guarantee against
1011
1192
  every power-loss or filesystem-failure scenario.
1012
1193
  - **Parent directories:** `write` does not create them.
1013
- - **Line deletion:** unsupported. Emptying a line is not deleting it.
1194
+ - **Replacement addressing:** `edit` replaces one whole block of lines. The
1195
+ addresses name individual original lines; there is no range syntax such as
1196
+ `01:03` in `OLD`, and no regex or search mode.
1014
1197
  - **Configuration:** there are no configuration files, environment-variable
1015
1198
  options, plugins, or interactive prompts.
1016
1199
  - **Read performance:** only selected lines are decoded and formatted, but the
@@ -1070,15 +1253,20 @@ Addresses are hexadecimal. `64` means decimal 100. Decimal 64 is hexadecimal
1070
1253
 
1071
1254
  The file has at least 256 lines, so all displayed addresses use three digits.
1072
1255
 
1073
- #### “My content line `dead: text` became a separate edit”
1256
+ #### “`dead: text` in `NEW` is inserted literally”
1074
1257
 
1075
- `dead` is valid hexadecimal. Escape it as `\dead: text` on a continuation
1076
- line.
1258
+ Replacement lines carry no prefixes and are never parsed as addresses. A line
1259
+ such as `dead: text` in `NEW` becomes file content exactly as supplied. In
1260
+ `OLD`, every line must be a valid `HEX: original content` header, so a line
1261
+ such as `dead: text` there is rejected as malformed
1262
+ (`expected 'HEX: original content', got: ...`).
1077
1263
 
1078
- #### “`02:` did not remove line 2”
1264
+ #### “My `edit` left a blank line I did not want”
1079
1265
 
1080
- That syntax replaces line 2 with an empty line. Line deletion is not
1081
- implemented.
1266
+ With the verified-`OLD` syntax, removing a line is explicit: give the line's
1267
+ verified original content in `OLD` and pass `NEW` as the empty string `''`.
1268
+ An empty **`NEW` line** is different: it leaves one blank line in place, and
1269
+ a file emptied that way never reaches 0 bytes.
1082
1270
 
1083
1271
  #### “I only see 1000 lines”
1084
1272
 
@@ -1132,9 +1320,9 @@ calls. It covers:
1132
1320
  - Single, finite, and open-ended ranges
1133
1321
  - Empty files, unterminated final lines, and the 1000-line cap
1134
1322
  - Exclusive creation and exact multiline content
1135
- - Multiple original-address edits and multiline expansion
1136
- - Empty replacements, duplicate and out-of-range rejection
1137
- - Escaped headers and standard input
1323
+ - Whole-block replacement, non-contiguous addresses, and deletion
1324
+ - Mis-edit guard, duplicate and out-of-range rejection
1325
+ - Blank-line `NEW`, standard input, and terminator semantics
1138
1326
  - CRLF and final-newline preservation
1139
1327
  - Permissions, symbolic links, invalid UTF-8, and failed replacement cleanup
1140
1328
  - Help, version, usage errors, and the real `python -m rwe` surface
@@ -1306,15 +1494,15 @@ Suppose the new version is `0.2.0`.
1306
1494
 
1307
1495
  - `src/rwe/cli.py` contains a small hand-written argument dispatcher rather
1308
1496
  than `argparse`, avoiding that startup cost.
1309
- - Hexadecimal validation and edit-header parsing avoid importing `re`.
1497
+ - Hexadecimal validation and `OLD` line parsing avoid importing `re`.
1310
1498
  - `tempfile` is imported only when `edit` needs it, keeping `read` and `write`
1311
1499
  startup lighter.
1312
1500
  - `read` formats at most 1000 selected lines, then counts remaining newlines
1313
1501
  in 1 MiB binary chunks to determine total width.
1314
1502
  - `write` uses `O_WRONLY | O_CREAT | O_EXCL` for atomic no-overwrite creation.
1315
- - `edit` parses the entire edit argument, validates against the original,
1316
- replaces addresses bottom-up, and saves via a sibling temporary file and
1317
- `os.replace`.
1503
+ - `edit` verifies every `OLD` line against the original file, removes the
1504
+ addressed lines, inserts each pair's `NEW` at that pair's lowest
1505
+ address, and saves via a sibling temporary file and `os.replace`.
1318
1506
  - Expected failures use the internal `RweError` exception and produce concise
1319
1507
  English messages rather than tracebacks.
1320
1508