leeand00
leeand00

Reputation: 26402

Search and replace all but the last line in sed?

I know if you specify :1,$-1s/stuff/noun/g in vim you can run a search and replace on the entire file, excluding the last line.

Is there a syntax that can specify that you want to run a search and replace on all but the very last line in the file in sed?

Upvotes: 0

Views: 411

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 755016

sed -e '$q' -e 's/stuff/noun/g' file

Quit after printing the last line; otherwise, do the substitution.

See also sed line range all but the last line; it would recommend:

sed '$! s/stuff/noun/g' file

Upvotes: 1

Related Questions