[talk] insert line after matched pattern (fwd)

Steven Kreuzer skreuzer at exit2shell.com
Wed Aug 19 12:18:22 EDT 2015


> On Aug 19, 2015, at 11:59 AM, freebsd at fongaboo.com wrote:
> 
> 
> Anyone know how to insert a line after a matched pattern using sed, awk or any other method that gets the job done? Any tutorials I find seem not to work in BSD due to GNU sed vs. non-GNU?


With awk:

$ echo 'FIRST_LINE\nLAST_LINE' | awk '1;/FIRST_LINE/{print "NEWLINE"}'
FIRST_LINE
NEWLINE
LAST_LINE

The '1' is a shortcut for {print} so it will always print the line. However, if FIRST_LINE gets matched, it will also print NEWLINE


More information about the talk mailing list