Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_wiki:sed [2016/02/05 13:29] billdozor [Remove Lines] |
linux_wiki:sed [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 6: | Line 6: | ||
**Checklist** | **Checklist** | ||
- | * Linux distro with the ' | + | * Distro(s): Any |
+ | * Package: | ||
---- | ---- | ||
- | ===== Insert Lines ===== | + | ====== Print Lines ====== |
+ | |||
+ | Different ways to print specific lines. | ||
+ | |||
+ | Print only line 5 pattern space< | ||
+ | * -n => silent; do not print the entire file | ||
+ | |||
+ | Line 5, don't delete it<code bash>sed ' | ||
+ | * !d => don't delete | ||
+ | |||
+ | Print up to line 5, quit and delete the rest of the output< | ||
+ | * q => quit/stop processing more input | ||
+ | * d => delete the pattern space (removes all but line 5 from output) | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Swap Patterns ====== | ||
+ | |||
+ | Edit files by swapping pattern spaces. | ||
+ | |||
+ | * Before< | ||
+ | # Generated by NetworkManager | ||
+ | search local | ||
+ | nameserver 208.67.222.222 | ||
+ | nameserver 208.67.220.220</ | ||
+ | * After< | ||
+ | # Generated by NetworkManager | ||
+ | search local | ||
+ | nameserver 8.8.8.8 | ||
+ | nameserver 208.67.220.220</ | ||
+ | * -i => In-line editing | ||
+ | * s => swap | ||
+ | * g => global swap (swap every match, not just the first one) | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ====== Insert Lines ====== | ||
Insert lines before a found matched pattern. | Insert lines before a found matched pattern. | ||
Line 35: | Line 72: | ||
</ | </ | ||
- | ==== Insert at first line ==== | + | ===== Insert at first line ===== |
Insert also works against line numbers. | Insert also works against line numbers. | ||
Line 54: | Line 91: | ||
---- | ---- | ||
- | ===== Append Lines ===== | + | ====== Append Lines ====== |
Append lines after a found matched pattern. | Append lines after a found matched pattern. | ||
Line 80: | Line 117: | ||
---- | ---- | ||
- | ===== Remove Lines ===== | + | ====== Remove Lines ====== |
Remove lines that match a pattern. | Remove lines that match a pattern. |