[sed] replace string?
Dear all,
I'm sorry that I can't understand when I man sed. What I want to do are replacing some string and inserting strings in first line. The strings I want to replace, ex: first second; ==> //first second; #include <FlexLexer.h> ==> #include "FlexLexer.h" I may insert a string,such as #include "myheader.h", to first line of some file. How should I do? Thanks for your help. Best Regards, chuanyung. |
Here are some examples:
One file sed s/\<FlexLexer.h\>/\"FlexLexer.h\"/ yourfile.c >yourfile.new; mv yourfile.new yourfile.c a few files for i in 'file1 file2 file3' do sed s/\<FlexLexer.h\>/\"FlexLexer.h\"/ $i >$i.new mv $i.new $i done A dir tree of files for i in `find -name file\*` do sed s/\<FlexLexer.h\>/\"FlexLexer.h\"/ $i >$i.new mv $i.new $i done -Matt Not tested but should work ... |
"info sed" is much explainig than "man sed".
If you're not familiar with "info" try readingi "info info" Here's more sed explanation, examples, tricks.... http://www.faqs.org/faqs/editor-faq/sed/ http://main.rtfiber.com.tw/~changyj/sed/ http://sed.sourceforge.net/grabbag/ |
Thanks, I finished it.
|
All times are GMT -5. The time now is 09:26 PM. |