Grep showing all files name of the directory

Hi All,

Can any one help me here.I'm getting whole files name of the directory along with the grep result.

below is the code

 
var=`grep -i '127.3.3.1' _record`
echo $var

What is "whole files name"?
Is your grep aliased?

Thanks for reply Rudic !!

Whole files name here means all the other files name which is present in the current directory.

For you refrence o/p of the above code.

 
"26731","47710","TEST","ADMIN","127.3.3.1","select 1 1.cron_dup 1.out 1.sql 912650.pln abc.out aginity A.out B.out check234 C.out create_mytable create_mytable.out dynamictables1 empty et1_region_flat_file exclusionfield1 exclusionfield1.out exclusionfilterchar file1 final_report.out fstm greatest.cpp greatest.o_spu10 greatest.o_x86 health.sh health_test.sh hostbackup if_test load1.dat long long_aginity longrunning.csv longrunning_edit.csv longrunning_edit.csv_old msg1.out msgatach.out msgattach.out msgBody.txt msg.out MSTR mytest_2370271.pln my_test_table_in_place2370368.pln Netezza permission query_5674337_final query_test rav_a.out _record region row.out runaway runaway_1 runaway_3 runaway_3_msg.out runaway_new.sh runaway.out runaway_priya.sh runaway_test sample.out session size_info_old.out size_info.out size.out sql_not_in_place_of_view.out sql_not_in_place_of_view.out1 sql_table_in_place_of_view.out sql.txt sql.txt2 sqltxt26 sqltxt26.out sql.txt2_format sql.txt2.out stats sts.log sytm.out sytm.txt TABLE1.1 temp1 temp1.csv temp1.out temp2.out temp3.out test000 test007 test101 test101.csv test102 test103 test104 test105 test1.sh test222 test2222 test222_msg.out test22.sh test23.sh test333 test333.out test444 test_aatch test_case test_create test_create.create_out test_create.create.out test_diag test_grep_ip testkkk testkkk.out test_session 

Well, I guess that's the line in _record that has 127.3.3.1 in it.

No Rudic.

These are the files name in current directory.Only till select is the content in the file '_record'

Is _record a flat file, or a directory?

Is that your entire script, or is there some other stuff around it?

_record is a flat file

This is the only thing in the script.

 
var=`grep -i '127.3.3.1' _record`
echo $var

I assume you've checked that _record doesn't actually have a bunch of filenames in it? What does the relevant line look like in the file?

hi try
can you try

cat _record| grep -i <your pattern>

instead of

grep -i <pattern> <filename>

ideally they both should be producing the same result.

I presume your file "_record" contains some DB-statement, maybe something like "select * from ...". Your problem is a simple case of neglecting proper quoting in the shell. Try the following:

echo "*"
echo *

and you will notice that the first produces a single asterisk while the second one produces a list of all files, quite similar to the output of "ls". The reason is, that the shell evaluates some expressions - the asterisk being among them - itself, instead of passing it to the program. Issue a

ls -l *

and the following will happen: first "*" is being expanded to a list of all file names, then "ls" is given this list and displays the files one by one. The same has happened here: by

echo $var

you basically have executed a

echo ... select * from ...

and the asterisk is duly expanded. As you should NOT USE BACKTICKS UNDER ANY CIRCUMSTANCE (really!) you should modify your code this way:

var=$(grep -i '127.3.3.1' _record)
echo "$var"

I hope this helps.

bakunin