This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
fuss:sed [2014/06/27 12:21] – [Insert a Space After Every Character] office | fuss:sed [2022/04/19 08:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Stripping Comments and Newlines ====== | ||
+ | |||
+ | <code bash> | ||
+ | cat / | ||
+ | </ | ||
+ | |||
+ | First part: | ||
+ | <code bash> | ||
+ | sed -e ' | ||
+ | </ | ||
+ | strips any line beginning ('' | ||
+ | |||
+ | Next part: | ||
+ | <code bash> | ||
+ | sed -e ': | ||
+ | </ | ||
+ | |||
+ | - create register '' | ||
+ | - put newline ('' | ||
+ | - substitute all ending newlines ('' | ||
+ | - repeat with register '' | ||
+ | |||
+ | ====== Insert a Space After Every Character ====== | ||
+ | |||
+ | Using bash: | ||
+ | <code bash> | ||
+ | cat test | sed -s ' | ||
+ | </ | ||
+ | |||
+ | Note that '' | ||
+ | |||
+ | ====== Insert a Line at a Given Position ====== | ||
+ | |||
+ | Suppose we have a text file containing the following lines: | ||
+ | < | ||
+ | number 1 | ||
+ | number 3 | ||
+ | </ | ||
+ | |||
+ | and that we want to insert '' | ||
+ | |||
+ | <code bash> | ||
+ | sed -i ' | ||
+ | </ | ||
+ | |||
+ | where the parts of the fragments represent: | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | which will modify the file in-place such that the contents of the file after the insertion becomes: | ||
+ | < | ||
+ | number 1 | ||
+ | number 2 | ||
+ | number 3 | ||
+ | </ | ||
+ | |||
+ | ====== Print all Lines Between Bounds ====== | ||
+ | |||
+ | To print out all the lines between '' | ||
+ | <code bash> | ||
+ | sed -n ' | ||
+ | </ | ||