sed basics - miraj/tools GitHub Wiki

Basic Syntax sed '' sed edits the contents of the file according the rules The resultant file is just printed to screen (console or stdout). The original file is unchanged

sed rules:

Style 1

/pattern/ followed by command linenumber followed by command

eg: //q stops printing when is found. q is the command here

/^[ \t]*$/d

deletes blank lines. 'd' is command here

1d deletes the first line of the file

$d

deletes the last line of the file

TODO: give search and replace example here

Style 2

/start pattern/,/end pattern/ follewed by command /start line number/,/end line number/ follewed by command

The command will be applied only for the lines between start and end

eg:

/

/,/</head>/s/HTML4/HTML5/

s is the command here. so does search and replace

100,430d

delete lines from 100 to 403

style 3

Just the command, pattern and line number is missing In such cases the command is applied to all the lines. simple

⚠️ **GitHub.com Fallback** ⚠️