It took me a while to figure out how to do this, so posting in case anyone else is looking for the same.
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- bash print whole line after splitting line with if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
For adding a newline after a pattern, you can also say:
Quoting GNU sed manual:
EDIT:
Incidentally, this happens to be covered in sed one liners:
This sed command:
Finds the line with: pid = run
file.txt before
and adds a linebreak after that line inside file.txt
file.txt after
Or if you want to add text and a linebreak:
file.txt after
It will add a return after the pattern while
g
will replace the pattern with a blank line.If a new line (blank) has to be added at end of the file use this:
Another possibility, e.g. if You don't have an empty hold register, could be:
Explanation:
/pattern/{...}
= apply sequence of commands, if line with pattern found,p
= print the current line,;
= separator between commands,s/.*//
= replace anything with nothing in the pattern register,then automatically print the empty pattern register as additional line)
A simple substitution works well:
Example :
To be standard compliant, replace \n by backslash newline :