User Tools

Site Tools


linux:sed

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
linux:sed [2021/12/11 12:06] – created utedasslinux:sed [2022/09/12 00:30] (current) – external edit 127.0.0.1
Line 3: Line 3:
  
 ===== 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 '-n' flag.
 +
 +Forward dash ''/'' is usually a separator character. It is used to separate different commands and their arguments.
 +
 +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 '' 's/some text/other text/p' '' could be written as '''sKsome textKother textKp' ''.
 +
 +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> <code bash>
-sed -n ''+echo testfil.txt | sed -n '/something/p' 
 +</code> 
 + 
 +While the command to substitute comes before a string. To substitute "dude" with "shit": 
 +<code bash> 
 +echo testfil.txt | sed 's/dude/shit/' 
 +</code> 
 + 
 +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 's/dude/shit is fucked up/p' 
 +</code> 
 + 
 + 
 + 
 +===== Examples ===== 
 + 
 +<code bash> 
 +sed '/actual pattern/command' 
 + 
 +# ex 
 +sed '/Matches this string/p' # command p is printed. But since -d flag is not provided, so will everything else too 
 + 
 +sed -n '/Matches this string/p' # Only prints rows containing "Matches this string"
 </code> </code>
  
linux/sed.1639224399.txt.gz · Last modified: 2022/09/12 00:30 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki