Macky
Macky

Reputation: 443

Unix Cat : No such file or directory error

I have the following script

#!/bin/bash
set i=0;
while read line
do
  echo "$line";
  $i < cat "my.log" | grep -w '$line' | wc -l;
  echo "$i";
  i=0;
done < "test.txt"

test.txt has values like

abc
def
lmn

my log has values like

> INFO 2013-08-16 13:46:48,660 Index=abc insertTotal=11  
> INFO 2013-08-16 13:46:48,660 Index=abcd insertTotal=11  
> INFO 2013-08-16 13:46:48,660 Index=def insertTotal=11  
> INFO 2013-08-16 13:46:48,660 Index=abcfe insertTotal=11

The goal is to pick each value from the test.txt and to search for that pattern in the my.log file.

The number of times the pattern is found is assigned to the variable i.

I am going to check the value of i and if it is 0 or the pattern was not found then I want that pattern to be stored in another file.

Currently, I am getting

./parser.sh: line 7: cat: No such file or directory

I have tried the cat command on the command line and it has worked fine but it is giving this error from within the script.

Upvotes: 8

Views: 58036

Answers (2)

gregn3
gregn3

Reputation: 1774

I had error messages like:

cat: command not found
curl: command not found

It was caused by code like this:

export PATH=$1
export SERVER=$(cat s_remote)

curl $@ $SERVER$PATH

And the solution was to rename the PATH variable to something else. PATH is used locally by the shell, and setting it for a different purpose interferes with the shell.

Upvotes: 1

user1907906
user1907906

Reputation:

You are trying to use a file called cat as input to a command called 0. That won't work.

Instead of

$i < cat "my.log" | grep -w "$line" | wc -l;

do this:

i=$(cat "my.log" | grep -w "$line" | wc -l)

See the question Difference between single and double quotes in Bash for a discussion of quotes and http://tldp.org/LDP/abs/html/commandsub.html for a description of command substitution in bash.

Upvotes: 7

Related Questions