awk call in bash function called with arugments not working, something lost in translation?
Hello,
I have this awk code in a bash script to perform a find and replace task. This finds one unique line in a file and substitutes the found line with a replacement.
This works well. It is rather involved for a simple find and replace but there are other conditions to consider. First, the line with $look_for is only unique in live code. The string may also exist in lines that have been commented out. Lines with a leading comment character need to be ignored. Also, $look_for often contains spaces and/or special characters that need to be escaped. I have had allot of trouble defining such values in awk using -v. Exporting the value of the string I am looking for to an environment variable allows me to use test the value in the awk call, including any spaces and necessary escape characters. I unset the environment variables immediately afterwords.
I have a dozen or so of these tasks to perform, so the logical structure is to have this code in a function to which the values for $filename, comment_ch, $look_for, and $replace_with are passed in the call. I have set it up in a function and printed the values from inside the function.
the code looks like,
This correctly prints the argument values from inside the function but the output I get is just a few lines with a single space. This doesn't make any sense. I am guessing that there may be some issue with the local environment inside the subshell for the function or the call to awk, but if ENVIRON["f_look_for"] evaluates to uninitialized, based on the logic in the awk code I would expect the entire unmodified file to be printed since neither the $comment_ch or $look_for would ever be found.
I'm not sure what to try next so I thought I would post.
Hi ,
I have three funcions f1, f2 and f3 .
f1 calls f2 and f2 calls f3 .
I have a global variable "period" which i want to pass to f3 .
Can i pass the variable directly in the definition of f3 ?
Pls help .
sars (4 Replies)
Hi,
I have the following statement which parses a string for me and prints it out:
l_comp="dc000.runksh.test.ksh|
$g_sql/dc0000.runksh_test.sql|new.dat|control.ctl"
echo $l_comp | awk -F"|" '{ for ( i = 1; i <= NF; i++) { print $i; } } '
Rather then printing the data, I would like to... (5 Replies)
Hello.
Looking for a method of modularizing my bash script, I am stuck with such a problem. For example, I have:
MODULE_NAME="test"
FUNCTION_NAME="run"
How do I can a function with name test_run? (4 Replies)
Hello,
I have a problem with package and name space.
require "/Mehran/DSGateEngineLib/general.pl";
use strict;
sub System_Status_Main_Service_Status_Intrusion_Prevention
{
my %idpstatus;
my @result;
&General_ReadHash("/var/dsg/idp/settings",\%idpstatus);
#print... (4 Replies)
Dear all,
Could you please advice as I when call function i found the following error
" refills: command not found" note that refills is function name.
following also the function and how i call it
function refills
{
echo "formatting refills and telepin" >> $log
awk -F,... (20 Replies)
Hi,
I have the following code in which i am trying to find ceil of 10th & 11th fields. For finding ceil i have a function in the awk statement. When i test it for some values say on command line it gives correct response(say $10=0 & $11=750). But when the same value occurs in a file having more 3... (5 Replies)
I've created a tag in the makefile:
mytag: $(shell ${PWD}/script.sh)
When i do: make clean - the script is executed
When i perform make or make mytag the script is again executed with the output:
make: Nothing to be done for mytag
What i want ?
I want script.sh to be executed only... (0 Replies)
My requirement is to call function ("fun1") from awk, and print its returned value along with $0.
fun1()
{
t=$1
printf "%02d\n", $t % 60;
}
echo "Hi There 23" | awk '{print $0; system(fun1 $3)}'
Any suggestions what to be modified in above code to achieve requirement.. (5 Replies)