Error while reading variable from a file in perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error while reading variable from a file in perl script
# 1  
Old 06-14-2014
Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error.


File abc.ini content

# database name
DBname =UATBOX

Code:
my $ex_stat;
my $cmd_output;

$ex_stat = "\Qawk '/^DBname/{print substr(\$2,2)}' abc.ini\E";

$cmd_output = `$ex_stat`;

if ($cmd_output) {
    print "ERROR\n";
}
print "CMD OUT: $cmd_output\n";

Error:
sh: awk '/^DBname/{print substr($2,2)}' abc.ini: No such file or directory
CMD OUT:

When I execute the command listed in the script output i.e. awk '/^DBname/{print substr($2,2)}' abc.ini, it executes fine and gives the desired output but in the script it gives error.

I would like to know where is the error.
# 2  
Old 06-14-2014
I think you don't need quote-meta here. If you are sure your fiile abc.ini does present, the quote-meta probably putting it as abc\.ini

Try without them

Code:
$ex_stat = "awk '/^DBname/{print substr(\$2,2)}' abc.ini";

# 3  
Old 06-16-2014
thanks clx, it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl : reading data from dumper variable

Hi team, # PERL I have Dumper variable in perl and containing the below data and trying to fetch value and name from the reference variable. $VAR1 = { 'retainSysIds' => 'true', 'variables' => , 'name' => , ... (4 Replies)
Discussion started by: giridhar276
4 Replies

2. Shell Programming and Scripting

Error in reading variable in shell script

Hello all, I have small script: # SCRIPT COMMONFILEPATH=$WORKDIR/samples/... (4 Replies)
Discussion started by: emily
4 Replies

3. Shell Programming and Scripting

Need help with perl script with a while loop reading file

Good morning, I appreciate any assistance that I can get from the monks out there. I am able to get this to work for me so that I can do a hostname lookup if I only specify one hostname in the script. What I want to do is have a file with hostnames and do lookups for each name in the file. Here is... (1 Reply)
Discussion started by: brianjb
1 Replies

4. Shell Programming and Scripting

Error while reading from a file in shell script

Hi All, I'm writing a script to read a file line by line and then perform awk function on it. I am getting an error . My file has one name in it "James". I'm expecting my o/p to be youareJamesbond James ./users.sh: line 7: =: command not found #script to read file line by line #adding... (5 Replies)
Discussion started by: Irishboy24
5 Replies

5. Shell Programming and Scripting

Perl Script for reading table format data from file.

Hi, i need a perl script which reads the file, content is given below. and output in new file. TARGET DRIVE IO1 IO2 IO3 IO4 IO5 ------------ --------- --------- --------- --------- --------- 0a.1.8 266 236 ... (3 Replies)
Discussion started by: asak
3 Replies

6. Shell Programming and Scripting

Help need in perl script reading from file

Need perl script, data file will be csv format. I have text file contains 2 colums. Filename Foldernumber aaaa 13455 bbbb 23465 cccc 26689 I have two location 1. files present and 2. folders present. I need to search for file and folder if folder... (3 Replies)
Discussion started by: hnkumar
3 Replies

7. Shell Programming and Scripting

SOLVED: reading config file in a perl script

Hi! I have a need to do this in Perl. script.pl -config file The script would be doing a wget/LWP on a URL which is defined in the config file. So when I run the script it should return either one of these conditions - 1) OK with exit status 0. Should also print "wget URL" 2)... (6 Replies)
Discussion started by: jacki
6 Replies

8. Shell Programming and Scripting

Help with perl script while reading a file

Hi Everyone, I am very new to perl, but came across a situation wherein I have to read a c++ header file and write the datatype, its identifier and also the length to an excel file. There can be other header files, in the directory but I should browse through the file which has only "_mef:" string... (9 Replies)
Discussion started by: ramakanth_burra
9 Replies

9. Shell Programming and Scripting

Reading each line of a file in perl script

HI I need to read each line (test.txt) and store it in a array (@test) How to do it in perl. Suppose i have a file test.txt. I have to read each line of the test.txt file and store it in a array @test. How to do it in perl. Regards Harikrishna (3 Replies)
Discussion started by: Harikrishna
3 Replies

10. Shell Programming and Scripting

perl not reading my variable

I'm trying to make changes in a file using the following bash script: #!/bin/bash MYHOME=`echo $HOME` README=$MYHOME"/environment" IAM=`whoami` CHANGEPATHLIST="TALOG TACONFIG TAINFO TAWORK TMPSPACE" for var in $CHANGEPATHLIST do perl -pi -e 's/sacuser1/$IAM/ if m/$var/' $README... (3 Replies)
Discussion started by: yoonixq4u
3 Replies
Login or Register to Ask a Question