This shows you the differences between two versions of the page.
| Previous revision | |||
| — | fuss:sed [2025/10/21 23:26] (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 ' | ||
| + | </ | ||
| + | |||
| + | ====== Normalizing Paths ====== | ||
| + | |||
| + | One way to normalize filenames is to pass the name through the streamline editor, sed: | ||
| + | <code bash> | ||
| + | echo "/ | ||
| + | </ | ||
| + | in order to remove unwanted characters. | ||
| + | |||
| + | The hexadecimal set that '' | ||
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.