Sponsored Content
Top Forums Shell Programming and Scripting find and replace text with a variable? Post 82177 by vgersh99 on Monday 29th of August 2005 01:53:45 PM
Old 08-29-2005
Quote:
Originally Posted by doublejz
Is there a way that I can make the following work with using variables?

perl -pi -e 's#blah#hrm#ig' replacetext

but like this

var=blah
perl -pi -e 's#$var#hrm#ig' replacetext
yes, there is - by using double quotes.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and replace the value in a variable

I have a variable whose value is I="user1:x:1100:1200:ID for user1:/home/user1:/bin/ssh-dummy-shell" I want to replace the last part '/bin/ssh-dummy-shell' with '/bin/true' I tried using sed but it garbled sed 's/\/bin\/ssh-dummy-shell/\/bin\/true' $I Thanks for the help (5 Replies)
Discussion started by: aajmani
5 Replies

2. UNIX for Dummies Questions & Answers

Find and replace text

test 100 abc test 134 bcd test 356 cdf test 831 dfg test 720 fgh Please advise how can I replace the abc, bcd....with ABC, BCD.... (1 Reply)
Discussion started by: bobo
1 Replies

3. UNIX for Dummies Questions & Answers

Find and replace text PLEASE HELP

Dear friends please help, I have a large data file with few hundred lines. A small example is shown below: datafile is a file with few hundred lines with the third column has many different character stings: test 100 abc test 134 bcd test 356 cdf test 831 dfg test 720 fgh I need to... (6 Replies)
Discussion started by: bobo
6 Replies

4. Shell Programming and Scripting

find and replace variable

Is there an easy way of doing this cat file1 jkasjhjgfg LTRIM(RTRIM(aa_bb_cde)) aragsfdg LTRIM(RTRIM(aa_bb_cde)) aregfafdgfg sdgsfdagdfg gadfg eafgsadgsa asdgsfdgag LTRIM(RTRIM(aa_bb_cde)) rfghsdfhd I want to replace each occurence of LTRIM(RTRIM($x)) with LENGTH(LTRIM(RTRIM($x)))=0... (4 Replies)
Discussion started by: alfredo123
4 Replies

5. UNIX for Dummies Questions & Answers

sed to replace text with a variable

I'm trying to replace text in a file with text from a variable I have the following in my script, but its not working: #!/bin/ksh echo "Enter the path to load scripts" read x echo "updating the templates" sed "s/CHANGE_ME_TO_LOAD_PATH/"$x"/g" LoadFiles.sh > LoadFiles2.sh I thought... (1 Reply)
Discussion started by: orahi001
1 Replies

6. Shell Programming and Scripting

replace text in file using variable

Hi, I'm making a script that automaticaly set file size and path in xml file. I tried with : sed -i 's/BOOTPATH/TEST/g' file.xml it works fine but if I use a viriable : sed -i 's/BOOTPATH/$bootpathf/g' file.xml with this one, no change are made. I don't understand why. If a make a ... (13 Replies)
Discussion started by: Toug
13 Replies

7. Shell Programming and Scripting

Find and add/replace text in text files

Hi. I would like to have experts help on below action. I have text files in which page nubmers exists in form like PAGE : 1 PAGE : 2 PAGE : 3 and so on there is other text too. I would like to know is it possible to check the last occurance of Page... (6 Replies)
Discussion started by: lodhi1978
6 Replies

8. Shell Programming and Scripting

Find a variable in a file and replace its value

HI , I can't find a solution to the following: In a simple menu script I want to capture the input from the user with "read" and use it as a value in a variable Rempages="some_value" which is in a different script file. So I have to perform a search and replace for this variable and only... (4 Replies)
Discussion started by: svetoslav_sj
4 Replies

9. Shell Programming and Scripting

find and replace with variable -sed

Hi, I have a ksh script where I am trying to mask the password in the log files. $loc - is my directory $PGUIDE_DB_USER_PSW - is a variable that holds the password I am looking for find $loc/logs -type f -exec sed -i "s/$PGUIDE_DB_USER_PSW/*****/"g {} \; I get an error: ... (2 Replies)
Discussion started by: amitlib
2 Replies

10. UNIX for Dummies Questions & Answers

Replace variable string with text

Hi All, Hoping someone can help.... I am trying to work out how I can ammend a log file to remove variable strings in order to remove confidential information which I cant pass on. As an example I have used phone numbers. A large log file contains multiple lines containing something like the... (6 Replies)
Discussion started by: mutley2202
6 Replies
HTML::Template::Compiled::Reference(3pm)		User Contributed Perl Documentation		  HTML::Template::Compiled::Reference(3pm)

NAME
HTML::Template::Compiled::Reference - A quick reference for HTML::Template::Compiled syntax TAGSTYLES
<TMPL_IF var><TMPL_VAR foo></tmpl_if var> <!-- TMPL_IF var --><!-- TMPL_VAR foo --><!-- /tmpl_if var --> <%if var %><%= foo %><%/if var %> Optional tagstyle 'tt': [%if var %][%= foo %][%/if var %] ACCESSING VARIABLES
<%= _.foo %> outputs foo in the cuurent position of the stash and is the same as <%= foo %> <%= .config.url %> goes to root of parameter stash; like $params->{config}->{url} <%= ..foo %> goes one level up in stash <%= list[3].keyname.method %> acts like: $stash->[3]->{keyname}->method TAGS
VAR <%var foo%> or <%= foo%> IF, IF_DEFINED, UNLESS, ELSIF, ELSE conditions like in Perl LOOP, WHILE, EACH for-loop and while-loop like in Perl. <%loop cds%><%= __counter__%>. Title: <%= _.title%><%/loop cds%> <%loop cds join=", " %><%= _.title%><%/loop cds%> <%while resultset.next%><%= __counter__%>. <%= _.foo %><%/while %> <%each hashref%><%= __key__ %>=<%= __value__ %><%/each %> (sorted alphanumeric) <%each hashref sort=alpha %><%= __key__ %>=<%= __value__ %><%/each %> (sorted alphanumeric) <%each hashref sort=num %><%= __key__ %>=<%= __value__ %><%/each %> (sorted numeric) <%each hashref sort=0 %><%= __key__ %>=<%= __value__ %><%/each %> (not sorted) WITH <%with cds[0].artist.fanclub%><%= _.address%><%= _.homepage%><%/with %> INCLUDE, INCLUDE_VAR <%include template.htc%> <%include_var param_with_template_name%> COMMENT, VERBATIM, NOPARSE <%comment explanation %> This will not appear in the rendered template. blah blah... <%/comment explanation %> SWITCH, CASE <%switch .config.language%> <%case de%>Hallo <%case es%>Hola <%case en,default%>Hello <%/switch .config.language%> PERL See section Perl in HTML::Template::Compiled ATTRIBUTES
Each attribute can be written as attribute=foo attribute="some thing" attribute='some "thing"' NAME You can omit the 'name=' here. <%if var%>var<%elsif name=var2%>var4<%/if%> Can be used in all tags. ESCAPE <%= message escape=html %> <%= params escape=url %> <%= params escape=js %> <%= some_var escape=dump|html%> Can be used in "VAR"-tags. DEFAULT <%= this.var.might_be_undef default="my fault" %> Can be used in "VAR"-tags. ALIAS <%loop cds alias="cd" %><%= cd.title %><%/loop cds %> Can be used in "LOOP" and "WHILE". Works like "SET_VAR" and is short for <%loop cds %><%set_var cd value=_ %><%= cd.title %><%/loop cds %> Useful for nested loops. SET_VAR <%set_var myvar value=.another.var %> <%set_var myvar2 expr="60 * 60 * 24" %> This creates a variable similar to local() in perl. To use such a var or an alias in includes, you must use "USE_VARS" in the include. USE_VARS <!-- recognize myvar and myvar2 as variables not parameter stash --> <%use_vars myvar,myvar2 %> myvar: <%= myvar %> JOIN <%loop cds join=", " %><%= _.title%><%/loop cds%> can be used in "LOOP" BREAK <%loop cds break="3" %> <%= _.title%><%if __break__ %> </%if %> <%/loop cds%> Sets "__break__" to 1 every xth loop. Can be used in "LOOP", "WHILE" and "EACH" OPTIONS
(loop)_context_vars <%= __index__ %> the current loop index starting at 0 <%= __counter__ %> the current loop index starting at 1 <%= __first__ %> true if first iteration <%= __last__ %> true if last iteration <%= __odd__ %> true if __counter__ is odd <%= __inner__ %> true if not last or first iteration <%= __key__ %> the key of an EACH iteration <%= __value__ %> the value of an EACH iteration <%= __break__ %> see L<"BREAK"> above <%= __filename__ %> filename of current template (since 0.91_001) <%= __filenameshort__ %> short filename of current template (since 0.91_001) perl v5.14.2 2012-05-26 HTML::Template::Compiled::Reference(3pm)
All times are GMT -4. The time now is 04:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy