LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-18-2009, 07:07 PM   #1
tiaratiara
LQ Newbie
 
Registered: Feb 2009
Posts: 7

Rep: Reputation: 0
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
=====================================================================
 
Old 03-18-2009, 07:35 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
man sed
/in-place




Cheers,
Tink
 
Old 03-18-2009, 07:38 PM   #3
hedgy102
Member
 
Registered: Mar 2009
Distribution: Debian,Centos
Posts: 30

Rep: Reputation: 16
Hi, sed is commonly used to transform information piped to other programs. It will not edit the file unless you specify the -i switch.
 
Old 03-18-2009, 07:44 PM   #4
Qbob
LQ Newbie
 
Registered: Mar 2009
Posts: 8

Rep: Reputation: 0
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 '
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed: insert a newline. Why does not it work? J_Szucs Linux - Software 4 03-19-2014 02:28 PM
LXer: Making the most of your browser screen real estate LXer Syndicated Linux News 0 05-26-2008 03:20 PM
can't get non-greedy matching to work in sed lumix Linux - Newbie 3 05-05-2008 08:12 PM
Using sed on several files at once davholla Linux - General 12 04-03-2005 08:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration