sed -i '/^foo/! s/^/bar/' file.txt
-i
change the file in place/^foo/!
only perform the next action on lines not!
starting with foo^foo
s/^/bar/
change the start of the line to bar
More Related Contents:
- Insert contents of a file after specific pattern match
- Why doesn’t `\d` work in regular expressions in sed? [duplicate]
- sed join lines together
- Whats the difference between sed -E and sed -e
- Is it possible to escape regex metacharacters reliably with sed
- Regex (grep) for multi-line search needed [duplicate]
- RE error: illegal byte sequence on Mac OS X
- How to use regex with find command?
- How to extract text from a string using sed?
- Using sed to delete all lines between two matching patterns
- Regex lookahead for ‘not followed by’ in grep
- sed one-liner to convert all uppercase to lowercase?
- Negative look-ahead in Go regular expressions
- Regex Until But Not Including
- How do you extract IP addresses from files using a regex in a linux shell?
- Regex to get the words after matching string [duplicate]
- How to replace a whole line with sed?
- How to invert a grep expression
- Why is sed not recognizing \t as a tab?
- Does lookbehind work in sed?
- Insert linefeed in sed (Mac OS X)
- Replace newlines with literal \n
- Replace a word with multiple lines using sed?
- replace a unknown string between two known strings with sed
- Why does sed require 3 backslashes for a regular backslash?
- Using sed and grep/egrep to search and replace
- How to change date format in sed?
- Replace all whitespace with a line break/paragraph mark to make a word list
- Understanding positive and negative lookaheads
- How to make “grep” read patterns from a file?