01-15-2008
Need help passing variables in shell script to perl one-liner
I'm writing a script to automate some post-install tasks on RHEL4 servers.
I need the following code to insert an 'A' in the middle of a string, then replace the string in a file. I know I can use sed to do this, but I'd like to use perl's in place edit so I don't have to write to a temp file, then overwrite the original.
Here's what I have so far:
mystr1=`grep Mlocal submit.cf | cut -d, -f3` #grab the string
mystr2=`echo $mystr1 | awk '{print substr($1,1,7) "A" substr($1,8)}'` #insert the 'A'
perl -i -p -e 's/$mystr1/$mystr2/' submit.cf #search and replace
The variables (mystr1 and mystr2) are not importing into the perl statement. I've tried exporting them with 'typeset -x' and using:
perl -i -p -e 's/$ENV{"mystr1"}/$ENV{"mystr2"}/' submit.cf #search and replace
Which works with:
perl -e 'print $ENV{"mystr2"}'
but not with search and replace
I know the search and replace syntax is correct because the following section of my script to uncomment the alias file works fine:
if [ `grep AliasFile submit.cf | cut -c1` = "#" ]
then
perl -i -p -e "s/#O AliasFile/O AliasFile/" submit.cf
fi
Any help is greatly appreciated.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello all,
i have a infile.txt text file which contains such variables:
aaa 123
asds 1323
asdsd 13434
lkjlkj 324324
23432 lkjlkj
24324 ljlkj
3j4lk 234kj3
and i want to pass them to my script such as:
./myscript $1 $2
where $1 is the first value in the first row and $2 is the second... (2 Replies)
Discussion started by: Bashar
2 Replies
2. Shell Programming and Scripting
Hi there,
I am trying to call a shell script from a Perl script. here is the code:
@args = ("sh", "someshellprg.sh", "a file handler", "an array");
system(@args) == 0
or die "system @args failed: $?";
in the shell program, I examine if the arguments exits using:
if
then echo... (5 Replies)
Discussion started by: pinkgladiator
5 Replies
3. Shell Programming and Scripting
Hi..
I am passing a variable in my shell function. I need to access it for an isql comand in the shell script.
However the isql o/p gives no results if i pass a variable in the command. The isql command works perfectly fine if i hardcore the table name.
My script is :
... (0 Replies)
Discussion started by: dikki
0 Replies
4. Shell Programming and Scripting
nawk '($1 ~ "1000") && ($1 ~ "5665" ) { sub ($6,"89");flag =1;print }' old.txt >> new.txt I want to set a flag in awk , if the both conditions are met. I want to pass this flag to shell Can anyone please help me on this (1 Reply)
Discussion started by: prav076
1 Replies
5. Shell Programming and Scripting
I have a perl script that opens a text file containing numbers on each line:
for example:
755993
755994
755995
755996
755997
755998
The perl script takes these numbers and store them as an array @raw_data, where I can access individual numbers by using $raw_data for the value 755993.... (2 Replies)
Discussion started by: xchen89x
2 Replies
6. Shell Programming and Scripting
Hi,
I need to pass a gnuplot value to a shell script. I have a main shell script (Main.sh) that has a bunch of gnuplot commands. Main.sh calls another gnuplot script (Child.gnu). A part of the code in Child.gnu is as follows:
sp '</data/src/scripts/results/plot_data.sh $col' u (A):2:3 w pm3d... (8 Replies)
Discussion started by: annazpereira
8 Replies
7. Shell Programming and Scripting
Thanks for giving your time and effort to answer questions and helping newbies like me understand awk.
I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk.
Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies
8. Homework & Coursework Questions
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
This is my assignment as a whole - Use SVG to present certain dynamic (the raw data should change at least once... (5 Replies)
Discussion started by: ChedWick
5 Replies
9. Shell Programming and Scripting
Hi.
I need to parse file and assign some values to variables, right now i do like below
MYHOMEDIR=`awk '/Home/ {print $NF}' output.txt`
MYSHELL=`awk '/Shell/ {print $NF}' output.txt`
PRGRP=`awk '/Primary/ {print $NF}' output.txt`
SECGRP=`awk '/Second/ {print $NF}' output.txt`
In this... (10 Replies)
Discussion started by: urello
10 Replies
10. Shell Programming and Scripting
Greetings all,
If I have a SH script that calls a PERL script in the following way:
perl $HOME/scripts/config.properties
And in the config.properties PERL file, this Perl script only sets a number of environmental parameters in the following way:
#!/usr/bin/perl
$VAR1 = (
... (3 Replies)
Discussion started by: gikyo12
3 Replies
LEARN ABOUT DEBIAN
debtags-submit-patch
DEBTAGS-SUBMIT-PATCH(1) User Commands DEBTAGS-SUBMIT-PATCH(1)
NAME
debtags-submit-patch - submit tag patches to http://debtags.debian.net
SYNOPSIS
debtags-submit-patch [-t TAG] [options] [patchfile [patchfile...]]
DESCRIPTION
Submits a tag patch to the Debtags website. Each patch file is submitted in a different query.
OPTIONS
--version
show program's version number and exit
-h, --help
show this help message and exit
-t tag, --tag=tag
tag the patch with the given string (default: 24f895dcbabc389804e5).
-q, --quiet
quiet mode: only output errors.
-v, --verbose
verbose mode: output progress and non-essential information.
--stdin
read patch from standard input.
--url=url
URL to submit to (default: http://debtags.debian.net/api/patch).
--dump-http-error=file
if the server returns an error, dump the contentsof the error page to the given file (default:discard the error page).
Patch files can be generated with 'debtags diff' or 'tagcoll diff'.
Patch submissions are marked with a tag of your choice. It does not need to identify yourself (but feel free to use your email address),
but reusing your tag allows to handle all your edits as if they were a single one. This helps greatly when tags are reviewed.
By default, a mostly persistent but anonymous tag is generated by hashing your passwd entry.
debtags-submit-patch 1.8 June 2012 DEBTAGS-SUBMIT-PATCH(1)