LinuxQuestions.org
Register a domain and help support LQ
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-11-2008, 03:56 PM   #1
ufmale
Member
 
Registered: Feb 2007
Posts: 385

Rep: Reputation: 30
quick way to add string to a text file


I have 100 files that I need to add <b> to the first line (begin) of the file and </b> to the last line (end) of the file. I just wonder if there is a quick and easy script I can run to do that?
 
Old 03-11-2008, 05:03 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

This sed statement puts the <b> and </b> in place:

sed -e '1s/^/<b>/' -e '$s/$/<\/b>/' infile

You can build a loop around that:

Code:
for THISFILE in `ls CRITEREA`
do
  sed -i -e '1s/^/<b>/' -e '$s/$/<\/b>/' $THISFILE
done
The -i options makes the changes 'in-place', test it first!!

Hope this helps.
 
  


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
How to replace a string in a text file jpan Linux - General 3 10-14-2012 07:17 PM
How can I append text to a string in a file HGeneAnthony Linux - Newbie 4 03-01-2007 01:16 PM
Need some quick help - how do I properly remove and add users in redhat 9 under text? orange400 Linux - General 7 04-18-2004 07:12 AM
How to pick a string from a text file? sdandeker Linux - General 1 02-12-2004 05:17 AM
Parsing a file for a string of text jamesmwlv Linux - General 2 12-02-2002 08:13 PM


All times are GMT -5. The time now is 05:39 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