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
sed substitution som.nitk Shell Programming and Scripting 5 03-21-2009 11:39 PM
Substitution Andyp2704 Shell Programming and Scripting 6 03-11-2009 07:35 AM
Difference between "Command substitution" and "Process substitution" royalibrahim Shell Programming and Scripting 3 12-15-2008 11:20 AM
Need help in substitution!!!! uLearner UNIX for Dummies Questions & Answers 3 03-06-2008 07:21 PM
ksh substitution solea Shell Programming and Scripting 2 08-09-2004 05:30 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-30-2009
tom.lee tom.lee is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
sed substitution

Using sed I'm trying to replace 'string' with '[[string]]' while retaining case and ignoring words with 'string' in it along with additional characters like 'strings' and those which already contain the [[]] wrapper. I'm hoping to do it with sed and the right expression, if possible.

Example:
Apple apple apples applet [[apple]]

In this example I would only want to convert 'Apple' to '[[Apple]]' and 'apple' to '[[apple]]' ignoring 'apples', 'applet' and '[[apple]]. I can substitue Apple but I lose my 'A' as it's changed to 'a.'

I'm attempting to autotag pages in my wiki so in the above example 'apples' and 'applet' don't represent existing pages and [[apple]] is already tagged.

Any ideas or has anybody been down this path before and already know I'm chasing a phantom?

Thanks
  #2 (permalink)  
Old 09-30-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Code:
echo 'Apple apple apples applet [[apple]]' | nawk -v str='apple' '{for(i=1;i<=NF;i++) if (tolower($i)==str) $i="[[" $i "]]"}1'
  #3 (permalink)  
Old 10-02-2009
tom.lee tom.lee is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
Your kung fu is strong--thank you!
Reply

Bookmarks

Tags
regular expression, sed, text manipulation

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 03:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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