The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
counting the lines matching a pattern, in between two pattern, and generate a tab d.chauliac Shell Programming and Scripting 4 03-19-2009 01:30 PM
pattern matching talashil Shell Programming and Scripting 2 02-10-2009 10:59 AM
comment/delete a particular pattern starting from second line of the matching pattern imas Shell Programming and Scripting 4 10-13-2008 02:37 AM
Pattern matching blue_bird UNIX and Linux Applications 3 10-08-2008 01:23 AM
help need for pattern matching HIMANI UNIX for Dummies Questions & Answers 10 01-22-2008 07:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2009
sky_rivers sky_rivers is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 4
sed pattern matching or passing variables

I need sed to add a "/>" to the end of a line that contains/starts with <meta.

current line is
HTML Code:
<meta name="keywords" content="kayword 1, kwyword2">
and should be
HTML Code:
<meta name="keywords" content="kayword 1, kwyword2 " />

i need something like this?
Code:
find . -name "*.html" -print0 | xargs -0 sed -i 's/<meta *>/<meta * \/>/g'
any help would be appreciated
  #2 (permalink)  
Old 03-17-2009
JCastro JCastro is offline
Registered User
  
 

Join Date: Mar 2009
Location: Canary Is. Spain
Posts: 5
Try:
Code:
 sed -n '/^<meta/p' test | sed 's\>\ />\g'
(sed takes only the lines starting with <meta and then changes > to /> )
  #3 (permalink)  
Old 03-17-2009
JCastro JCastro is offline
Registered User
  
 

Join Date: Mar 2009
Location: Canary Is. Spain
Posts: 5
....note that "test" must be your own file...
  #4 (permalink)  
Old 03-17-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Another approach:

Code:
sed 's!\(<meta.*\).$!\1 />!'
Regards
  #5 (permalink)  
Old 03-17-2009
sky_rivers sky_rivers is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 4
I tried
Code:
's!\(<meta.*\).$!\1 />!'
with find like this
Code:
find . -name "*.html" -print0 | xargs -0 sed -i 's!\(<meta.*\).$!\1 />!'
It works,but the result contains two ">" like this...
HTML Code:
<meta name="keywords" content="keyword1, keyword2"> />
i could run another sed to replace "> />", but if it is a easy improvement in the find section above?

I played with JCastro's example, but could not get it to work with find piped to sed

I am close and have enough to play further, but any further assistance would be great.
  #6 (permalink)  
Old 03-17-2009
sky_rivers sky_rivers is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 4
This works...
Code:
find lib/lib-pal -name "*.html" -print0 | xargs -0 sed -i 's!\(<meta.*\).$!\1 />!;s/"> \/>/" \/>/g'
Thanks

Last edited by sky_rivers; 03-17-2009 at 02:05 PM..
  #7 (permalink)  
Old 03-18-2009
sky_rivers sky_rivers is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 4
The following uses regular expression to remove any unlisted characters (including ">") and seems to be more predictable.
HTML Code:
find . -name "*.html" -print0 | xargs -0 sed -i s/\(<meta name[a-zA-Z \=\"\,\.\0-8\&\;\@-]*\).*/\1 \/>/
Sponsored Links
Closed Thread

Bookmarks

Tags
find, sed, xargs

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0