Sponsored Content
Top Forums Shell Programming and Scripting passing variables to sed inside script Post 90557 by tmarikle on Wednesday 23rd of November 2005 06:42:34 PM
Old 11-23-2005
eval should accomplish what you wish.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variables to sed

Hi folks, I'm looking for a solution to pass variables to a sed-command. I'm reading a lot of threats and also the q&a "How can I use a variable in sed?". None of these commands works. I'm using AIX 5.2. I want to do the following: NUMBER=` echo 38341` | sed -n '/$NUMBER/p' an obtained... (3 Replies)
Discussion started by: jfisch
3 Replies

2. Shell Programming and Scripting

passing variables to sed function in a script ....

Hello , I have a script named testscript.sh wherein I have two variables $var and $final (both of which contain a number) I have a sed write function inside this script as follows: sed '1,2 w somefile.txt' fromfile.txt Now , in the above i want to pass $var and $final instead of... (2 Replies)
Discussion started by: shweta_d
2 Replies

3. Shell Programming and Scripting

Passing variables to sed

Hi Folks, How can I make the following to work from a korn shell? old="OLDSTRING" new="NEWSTRING" file="myfile.txt" sed -n 's/$old/$new/gp' $file Thanks in advance rogers42 (3 Replies)
Discussion started by: rogers42
3 Replies

4. Shell Programming and Scripting

Passing UNIX commands inside sed

Hi, In sed, is it possible to match patterns by directly executing UNIX commands inside sed? For e.g. - sed "s/`cat file.txt | cut -d "|" -f2`/replace_string" Will the above command work? My expectation is to search for the second field in file.txt (file delimited by | ) and replace... (10 Replies)
Discussion started by: devanathann
10 Replies

5. Shell Programming and Scripting

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 <meta name="keywords" content="kayword 1, kwyword2"> and should be <meta name="keywords" content="kayword 1, kwyword2 " /> i need something like this? find . -name "*.html" -print0 | xargs... (6 Replies)
Discussion started by: sky_rivers
6 Replies

6. Shell Programming and Scripting

passing variables to sed in ksh

Hi, i need help passing variables to sed using ksh. My goal is to get particular data from log files. first i put a mark to the log files. echo "TEST_"`date + %m_%d_%Y_%T"` >markFile this will produce a 'markFile' which contain text like this TEST_06_01_2009_21:55:09 then i put the mark... (2 Replies)
Discussion started by: d.anggrianto
2 Replies

7. Shell Programming and Scripting

passing arguments to unix command or script inside tclsh

hi everobody kindly consider the following in tclsh I understand that we can do the following %exec UnixCmd arg1 arg2 but if I assinged the arguments to a list insde tclsh how can I use them back i.e %set ArgList %exec UnixCmd %exec Unixcmd $list %exec all the... (1 Reply)
Discussion started by: Blue_shadow
1 Replies

8. Shell Programming and Scripting

Help with passing multiple variables into SED

Hello I am hoping you can help. I use ksh in Solaris9 I am trying to pass user imputed variables into SED but for some reason can only get SED to recognize one variable. I have experimented with te below command with putting ' ' and " " in different places but I cant seem to get it to... (8 Replies)
Discussion started by: lostincashe
8 Replies

9. Shell Programming and Scripting

Passing variables to a sed function

Hi everyone, I've re-written some of our scripts to use more functions and I've run into a situation where passing a variable to a sed function does not work. My function is a one-liner sed command as follows: function StringSub() { sed -i "${1}/${2}/${3}/${4}" ${5} } Where ${1} through... (4 Replies)
Discussion started by: richardsantink
4 Replies

10. Shell Programming and Scripting

Passing variables from one script to another

Hi, this is the example i'm trying to do. script1.sh ABC="test.txt" ./script2.sh "$ABC" script2.sh INPUT="$HOMEDIR/$ABC" echo $INPUT when i run the 1st script it gives me ../home/ the test.txt is not passed into 2nd script. How can i resolve this. (2 Replies)
Discussion started by: gskris88
2 Replies
Perl::Critic::Policy::ErrorHandling::RequireCheckingRetuUserlContributedPerl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval(3pm)

NAME
Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval - You can't depend upon the value of "$@"/"$EVAL_ERROR" to tell whether an "eval" failed. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
A common idiom in perl for dealing with possible errors is to use "eval" followed by a check of $@/$EVAL_ERROR: eval { ... }; if ($EVAL_ERROR) { ... } There's a problem with this: the value of $EVAL_ERROR can change between the end of the "eval" and the "if" statement. The issue is object destructors: package Foo; ... sub DESTROY { ... eval { ... }; ... } package main; eval { my $foo = Foo->new(); ... }; if ($EVAL_ERROR) { ... } Assuming there are no other references to $foo created, when the "eval" block in "main" is exited, "Foo::DESTROY()" will be invoked, regardless of whether the "eval" finished normally or not. If the "eval" in "main" fails, but the "eval" in "Foo::DESTROY()" succeeds, then $EVAL_ERROR will be empty by the time that the "if" is executed. Additional issues arise if you depend upon the exact contents of $EVAL_ERROR and both "eval"s fail, because the messages from both will be concatenated. Even if there isn't an "eval" directly in the "DESTROY()" method code, it may invoke code that does use "eval" or otherwise affects $EVAL_ERROR. The solution is to ensure that, upon normal exit, an "eval" returns a true value and to test that value: # Constructors are no problem. my $object = eval { Class->new() }; # To cover the possiblity that an operation may correctly return a # false value, end the block with "1": if ( eval { something(); 1 } ) { ... } eval { ... 1; } or do { # Error handling here }; Unfortunately, you can't use the "defined" function to test the result; "eval" returns an empty string on failure. Various modules have been written to take some of the pain out of properly localizing and checking $@/$EVAL_ERROR. For example: use Try::Tiny; try { ... } catch { # Error handling here; # The exception is in $_/$ARG, not $@/$EVAL_ERROR. }; # Note semicolon. "But we don't use DESTROY() anywhere in our code!" you say. That may be the case, but do any of the third-party modules you use have them? What about any you may use in the future or updated versions of the ones you already use? CONFIGURATION
This Policy is not configurable except for the standard options. SEE ALSO
See thread on perl5-porters starting here: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-06/msg00537.html <http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-06/msg00537.html>. For a nice, easy, non-magical way of properly handling exceptions, see Try::Tiny. AUTHOR
Elliot Shank "<perl@galumph.com>" COPYRIGHT
Copyright (c) 2008-2011 Elliot Shank. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval(3pm)
All times are GMT -4. The time now is 08:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy