Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to use sed or awk to replace 5 lines in a smb file but I just don't have any idea how to deal with the newlines.

share|improve this question

put on hold as unclear what you're asking by jasonwryan, Jenny D, Braiam, maxschlepzig, Networker yesterday

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

6  
f course, sed and awk can do this, but I'm having a little trouble understaning exactly what your question is. What exactly is causing you trouble? Inserting new lines? Replacing them? –  frabjous Aug 25 '10 at 4:46

1 Answer 1

Sed is quite bad at this, because it operates one line at a time. The only decent technique I've ever seen to do this is this one, which involves storing the entire file in sed's hold buffer and then operating on it all at once:

sed -n '1h;1!H;${g;s/search/replace/;p;}'

If you can, it's much easier to use perl to accomplish this:

perl -0pe 's/search/replace/'

search can contain \ns to represent newlines

share|improve this answer
1  
+1 for the sed multiliner. –  Lazer Aug 29 '10 at 6:36

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