linux:sed
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:sed [2021/12/11 12:11] – [Using as regex to get stuff] utedass | linux:sed [2022/09/12 00:30] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== Using as regex to get stuff ===== | ===== Using as regex to get stuff ===== | ||
| By default, everything that is not deleted (by a delete command) is printed to stdout. To inhibit this, pass ' | By default, everything that is not deleted (by a delete command) is printed to stdout. To inhibit this, pass ' | ||
| + | |||
| + | Forward dash ''/'' | ||
| + | |||
| + | Truth to be told, almost any character can be used as a separator. The first character after the command seems to be used as a separator. Thus '' | ||
| + | |||
| + | sed takes a string as argument, which can contain commands, that in turn contain matching strings. | ||
| + | |||
| + | The string that is passed to sed must contain a valid command. A valid command is fucked up. It can be either the first character, or the trailing character. | ||
| + | |||
| + | For example the command to print a line that matches something would be | ||
| + | <code bash> | ||
| + | echo testfil.txt | sed -n '/ | ||
| + | </ | ||
| + | |||
| + | While the command to substitute comes before a string. To substitute " | ||
| + | <code bash> | ||
| + | echo testfil.txt | sed ' | ||
| + | </ | ||
| + | |||
| + | But you could also combine them, and print only the lines that matches the substitutions. Thus having commands both first and last in the string: | ||
| + | <code bash> | ||
| + | echo testfil.txt | sed -n ' | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ===== Examples ===== | ||
| <code bash> | <code bash> | ||
linux/sed.1639224684.txt.gz · Last modified: 2022/09/12 00:30 (external edit)
