sed doesn't work in the real files but on the screen
I need to add in lines in front of and in end of all the .html files in a folder.
I tried these codes, however, nothing happened in those html files when I opened them with Text editor. I could only see what I want to print out on the Terminal window.And I 'm sure I run the script in the right place. Any suggestion? ===================================================================== #!/bin/bash j=1 for i in *.html; do if [[ $j -lt 8 ]]; then < ${i} sed -n ' 1i\ <DOC>\ <DOCNO>cc_1_${j}</DOCNO> $i</DOC>\ ' fi j=$(($j+1)); done ===================================================================== |
man sed
/in-place Cheers, Tink |
Hi, sed is commonly used to transform information piped to other programs. It will not edit the file unless you specify the -i switch.
|
See the other replies about in-place editing, but if you want to be safe maybe it is worth changing your script to output to a new file. Then you can check it is doing the right thing before overwriting your original files. See modified line below:
Quote:
|
All times are GMT -5. The time now is 03:36 PM. |