Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

if i have a file

half a pound
of tuppenny rice
half a pound
that's the way
the money goes
pop goes the weasel

And I want to insert a line "of treacle" at line 4. so it should be

half a pound
of tuppenny rice
half a pound
of treacle
that's the way
the money goes
pop goes the weasel

how can I do this in sed for windows. I am using gnuwin32's sed.

share|improve this question
C:\Users\username>type afile.txt
half a pound
of tuppenny rice
half a pound
that's the way
the money goes
pop goes the weasel
C:\Users\username>

C:\>sed "4i\of treacle" afile.txt
half a pound
of tuppenny rice
half a pound
of treacle
that's the way
the money goes
pop goes the weasel
C:\>

you can use sed "3a\of treacle" afile.txt

i inserts before that line. 4i would be before line 4. a inserts after that line. 3a would be after line 3. so, 3a is the same as 4i.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .