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
Find & Replace string in multiple files & folders karthikn7974 Shell Programming and Scripting 4 04-29-2009 07:30 PM
shell script to find and replace string in multiple files pharos467 Shell Programming and Scripting 11 01-15-2009 11:40 AM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 11:47 PM
String replace perl script error MobileUser Shell Programming and Scripting 6 05-04-2006 09:18 PM
How to replace a string in multiple textfiles? dwidmer UNIX for Dummies Questions & Answers 1 11-21-2003 06:13 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 08-10-2009
bidbrooken bidbrooken is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 1
Thumbs down PERL: Replace multiple objects within a string

looking to replace parameters within a string with an external answer - with multiple replacements within a string %% will be used to wrap the objects to be replaced

i.e. hello %%title%% %%user%% from %%address%% you last %%action%% on %%object%%

the params will be used to make calls to a database to get the answers thenI need to substitute the answers back in.

I think I need to do this in two passed

first extract all the params and process them
then replace each param with it's results

my questions
- how do I get the params out to an array
- how do I substitute them back in
  #2 (permalink)  
Old 08-10-2009
durden_tyler's Avatar
durden_tyler durden_tyler is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2009
Posts: 518
Code:
$
$ echo "hello %%title%% %%user%% from %%address%% you last %%action%% on %%object%%" |
> perl -ne '@x=split /%%/;
>           ($x[1],$x[3],$x[5],$x[7],$x[9])=("TITLE","USER","ADDRESS","ACTION","OBJECT");
>           print "@x"'
hello  TITLE   USER  from  ADDRESS  you last  ACTION  on  OBJECT
$
tyler_durden
Reply

Bookmarks

Tags
extract, perl, regex, substitution

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 08:38 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