Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.