![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| passing two variables into a shell script? | Bashar | Shell Programming and Scripting | 2 | 05-15-2007 10:00 AM |
| passing variables to awk from ksh script | rein | Shell Programming and Scripting | 3 | 08-11-2005 11:29 AM |
| Passing variables to sql from batch shell in linux | rama71 | Linux | 2 | 06-28-2005 03:38 PM |
| Passing shell variables to awk program.. | Vishnu | Shell Programming and Scripting | 1 | 07-17-2004 10:04 AM |
| Passing variables from one script to another | tcoventr | UNIX for Dummies Questions & Answers | 2 | 06-18-2002 10:57 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|