Village
Village

Reputation: 24423

How to begin at line n in a file with sed?

When using sed as sed -i 's/pattern/replacement/g' ./file.txt, how can I tell sed to skip the first 10 lines of a file, and begin the replacements on the 11th line?

Upvotes: 2

Views: 2993

Answers (2)

Jotne
Jotne

Reputation: 41460

Same with awk

awk 'NR>10 {gsub(/pattern/,"repalcement")}1' file

Upvotes: 3

anubhava
anubhava

Reputation: 785471

You can use address before s command in sed:

sed -i.bak '11,$s/pattern/repalcement/g' file

Here 11,$ will skip first 10 lines and start replacement from 11th line onwards.

Upvotes: 10

Related Questions