LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 08-30-2009, 10:21 PM   #1
b-bri
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Adding (not replacing) a pattern match with a similar pattern?


I'm writing a bash script to search html files, and when I find any occurrence of an img src tag like this:

<img src="123-picture-normal.jpg" alt="some random user entered text" border="0">

I want to add a second line below it that looks like:
<img src="123-picture-thumbnail.jpg" alt="some random user entered text" border="0">

All I need to do is duplicate the line but replace "normal" with "thumbnail"

Each file can have multiple img src tags with different numbered jpgs.

I have a feeling this is a job for sed, but I'm struggling with it. Any ideas?
 
Old 08-30-2009, 11:46 PM   #2
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
Try
Code:
sed '/<img src="[0-9]*-picture-normal.jpg" alt="/{
h
s/-picture-normal.jpg" alt=/-picture-thumbnail.jpg" alt=/
x
G
}'
 
Old 08-31-2009, 12:36 AM   #3
b-bri
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Excellent - I knew it was possible. Thanks for showing me how.
 
  


Reply



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
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
Replacing a pattern using variable? shivarajM Linux - Software 1 04-30-2009 01:23 AM
pattern match : korn shell tostay2003 Programming 1 12-31-2008 12:08 PM
How to delete the file using pattern match? nishanthhampali Programming 3 04-16-2008 12:50 PM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM

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

All times are GMT -5. The time now is 08:12 PM.

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
Open Source Consulting | Domain Registration