grep can't open error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep can't open error
# 1  
Old 06-30-2010
Bug grep can't open error

Hi,

Thanks for all your help. This forum is excellent. I just learnt PERL over the last few weeks by coding and asking questions....

I have one more.

When I run my script I get the following error msg. The grep statement I have is

Code:
`grep "Number of jobs processed:" output | sort -u | awk '{print $5}'`;
 
Error :-  grep: can't open output

FYI - output is a variable which points to a file name and it does point to the right file name, when I displayed the variable.

I gave the back tick to allow PERL to bypass to Shell.

What is it complaining about this statement.

When I looked around on the forums - things were mentioned about

1) removing the quotes " " - Did not work
2) Tried saying $output - Did not work, More errors showed up

Please help

Thanks
nurani

Last edited by pludi; 06-30-2010 at 02:56 PM.. Reason: code tags, please...
# 2  
Old 06-30-2010
If output is Perl variable, then it should look like that:
Code:
`grep "Number of jobs processed:" $output | sort -u | awk '{print $5}'`;

And this line of code should be assigned to some other variable, like:
Code:
$out=`grep "Number of jobs processed:" $output | sort -u | awk '{print $5}'`;

# 3  
Old 06-30-2010
Bug Split file name from relative path

Ok,

The issue seems to be that my $output comes like this (whole path)

Code:
-rw-rw-r--  1  user3  box1  99999 Jun 29 12.00 /abc/def/xyz/filename

How do I just strip the "filename" from above. Can I do an awk o this and if so how. That's what I need to grep on.

Please provide the syntax.

With this whole thing passed to the grep, I am thinking grep doesn't have a clue about it.

Am I thinking right?

Thanks
nurani

Last edited by pludi; 06-30-2010 at 02:57 PM.. Reason: code tags, please...
# 4  
Old 06-30-2010
Yes, you are thinking right. Grep is expecting path, not ls output :P. And if you are using Perl, then getting that path is simple:
Code:
@a=split " ",$output;
$output=$a[8];

Put it before call to grep, and it should work.

Or in one step:
Code:
$output=(split " ",$output)[8];

# 5  
Old 06-30-2010
Bug grep can't open error ----- Continues

Hi,

Thanks for the code. I put that in and now my $output has the file name I need to grep.

Yet, "grep can't open error" shows up

This is what I added within the loop.

Code:
       @a=split " ",$output;
       $output=$a[8];
        print "new value of output\n";
        print "$output\n";

        @a=split "/",$output;
        $output=$a[4];
        print "new value of output with slash\n";
        print "$output\n";

Again, the grep that I have coded within the loop is like this

Code:
$CTR=`grep "Number of orders processed:" output | sort -u | awk '{print $5}'`;

Anything to do with the double quote " or single quote ' that I have.

Thanks
Nurani

Last edited by pludi; 06-30-2010 at 05:18 PM.. Reason: code tags, please...
# 6  
Old 06-30-2010
You missed "$" in variable name again:
Code:
$CTR=`grep "Number of orders processed:" $output | sort -u | awk '{print $5}'`;

# 7  
Old 06-30-2010
grep can't open error ----- Continues

Sorry,

I was trying on 1 box to make it work. I copied the wrong code.

I do have the $output as you mentioned.

Code:
$CTR=`grep "Number of orders processed:" $output | sort -u | awk '{print $5}'`;

Thanks
nurani

Last edited by pludi; 06-30-2010 at 05:19 PM.. Reason: code tags, please...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error when using vim to open files

Hi all, 1st post here. I'm on Solaris and currently, I get the following error if I try to use vim to edit anything: Error detected while processing function <SNR>6_initialize: line 2: E697: Missing end of List ']': E116: Invalid arguments for function <SNR>6_defineOption line 3: E10:... (6 Replies)
Discussion started by: fred2028
6 Replies

2. Shell Programming and Scripting

Awk: can't open error

Hi , In a directory i've the files in the following format pay:year:mon:11789604 pay:year:mon:17675644 --- and i need to get 4th part of the above file name so i used awk command in the below code #!/bin/ksh for test_data in pay* do txt_awk = awk -F':' '{print $4;}' $test_data ... (7 Replies)
Discussion started by: smile689
7 Replies

3. Emergency UNIX and Linux Support

Error when trying to start open office

Hi all I am receivng following error while running openoffice on linux system Please suggest and linux comman which can remove this error: (I) x.org loaded video driver of... (II) Loading /usr/lib64/xorg/modules/drivers/intel_drv.so (==) Depth 24 pixmap format is 32 bpp (III) ... (2 Replies)
Discussion started by: manigrover
2 Replies

4. Shell Programming and Scripting

Perl - Grep open file more then once.

Hi, I am using File::Find to go through a very large tree. I am looking for all xml files and open only those that contain a tag <Updated>. I then want to capture the contents of two tags <Old> and <New>. My problem is, after I open the file and do the first grep for <Updated> (which does... (3 Replies)
Discussion started by: OldGaf
3 Replies

5. Linux

ssmtp error : Cannot open <ip_address>:25

Hello, I am facing a problem with ssmtp mailing agent. I have installed and configured ssmtp in my RHEL5.3 system. I have written a shell script which sends mail to a couple of email id's. The script uses ssmtp to send mails. When I am running the scipt manually i.e. sh <script_name>.sh then... (3 Replies)
Discussion started by: senrooy
3 Replies

6. Red Hat

Error: Can't open display: :0.0

Hi, I get errors while running xclock from a non root user: # xclock --- this works fine # su - girish $ DISPLAY=:0.0; export DISPLAY $ xclock Xlib: connection to ":0.0" refused by server Xlib: No protocol specified Error: Can't open display: :0.0 $ I basically want to... (4 Replies)
Discussion started by: girish1428
4 Replies

7. Shell Programming and Scripting

grep: can't open /usr/dict/words

Hi All, If I use the "/usr/dict/words" inside the shell script, It is showing the error as, grep: can't open /usr/dict/words How can we resolve it? Thanks & Regards, Raja (2 Replies)
Discussion started by: Rajakct84
2 Replies

8. Shell Programming and Scripting

How to open an url and grep for a word

Hi All, I am new to shell scripting,Could any of you help me on this below :confused: -------------------- I need to write a shell script where i have open an url and grep for a particular word in the url and want to display it in a flatfile. Eg: Want to open yahoo.com and grep for yahoo... (1 Reply)
Discussion started by: sumithra
1 Replies

9. UNIX for Advanced & Expert Users

getting error when open vi editor

helo I install my product for koren language I m uisng RHEL -4 operating system now problem is whenever I open any file vi filename I got following error on the screen E557: Cannot open termcap file 'vt100' not known. Available builtin terminals are: builtin_ansi ... (1 Reply)
Discussion started by: amitpansuria
1 Replies

10. UNIX for Dummies Questions & Answers

cannot open error

Hi, Iam facing following error.please see the below script and error.Iam unable to attach error message to mail and its not sending mail also. vi Expedites_test.ksh "Expedites_test.ksh" 49 lines, 2276 characters #!/bin/ksh... (4 Replies)
Discussion started by: venu_cisco
4 Replies
Login or Register to Ask a Question