LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed doesn't work in the real files but on the screen (https://www.linuxquestions.org/questions/linux-newbie-8/sed-doesnt-work-in-the-real-files-but-on-the-screen-712628/)

tiaratiara 03-18-2009 06:07 PM

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
=====================================================================

Tinkster 03-18-2009 06:35 PM

man sed
/in-place




Cheers,
Tink

hedgy102 03-18-2009 06:38 PM

Hi, sed is commonly used to transform information piped to other programs. It will not edit the file unless you specify the -i switch.

Qbob 03-18-2009 06:44 PM

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:

< ${i} > ${i}_edited sed -n '


All times are GMT -5. The time now is 03:36 PM.