Sponsored Content
Top Forums Shell Programming and Scripting find and replace text with a variable? Post 82174 by doublejz on Monday 29th of August 2005 01:24:35 PM
Old 08-29-2005
Network find and replace text with a variable?

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
 

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
Devel::ArgNames(3pm)					User Contributed Perl Documentation				      Devel::ArgNames(3pm)

NAME
Devel::ArgNames - Figure out the names of variables passed into subroutines. SYNOPSIS
use Devel::ArgNames; sub foo { warn "foo() called with arguments: " . join(", ", map { defined() ? $_ : "<unknown>" } arg_names(@_) ); } foo($bar, $gorch, $blah[4]); DESCRIPTION
When print-debugging code, you will often ind yourself going: print "$foo is $foo, $bar is $bar" With this module, you can write a reusable subroutine easily: sub my_print_vars { my %vars; @vars{arg_names()} = @_; foreach my $var ( keys %vars ) { warn "$var is $vars{$var} "; } } my_print_vars($foo, $bar); This module doesn't provide dumping facilities because there are too many to choose from. This is a DIY kit ;-) EXPORTS
arg_names [ $level ] This function will return the names associated with the variables found on @_, at the level $level. If $level is not provided "arg_names"'s caller's caller will be used ("$level == 2" in that case). VERSION CONTROL
This module is maintained using Darcs. You can get the latest version from <http://nothingmuch.woobling.org/Devel-ArgNames/>, and use "darcs send" to commit changes. SEE ALSO
Data::Dumper::Simple, DB, Devel::Caller, Devel::Caller::Perl, PadWalker. AUTHORS
Ran Eilam Yuval Kogman <nothingmuch@woobling.org> COPYRIGHT
Copyright (c) 2007 Yuval Kogman. All rights reserved This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.1 2008-01-02 Devel::ArgNames(3pm)
All times are GMT -4. The time now is 04:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy