Question

i am a real beginner in csh/tcsh scripting and that's why i need your help. The problem is I have to go through some regular files in directories and find those files, that have their own name in its content. In the following piece of script is cycle in which I am going through paths and using grep to find the file's name in its content. What is surely correct is $something:q - is array of paths where i have to find files. The next variable is name in which is only name of current file. for example: /home/computer/text.txt (paths) and: text.txt (name) And my biggest problem is to find names of files in their content. It's quite difficult for me to write correct grep for this, cause the names of files and directories that i am passing through are mad. Here are some of them:

/home/OS/pocitacove/testovaci_adresar/z/test4.pre_expertov/!_1
/home/OS/pocitacove/testovaci_adresar/z/test4.pre_expertov/dam/$user/:e/'/-r
/home/OS/pocitacove/testovaci_adresar/z/test3/skusime/ taketo/   taketo
/home/OS/pocitacove/testovaci_adresar/z/test4.pre_expertov/.-bla/.-bla/.a=b
/home/OS/pocitacove/testovaci_adresar/z/test4.pre_expertov/.-bla/.-bla/@
/home/OS/pocitacove/testovaci_adresar/z/test4.pre_expertov/.-bla/.-bla/:
/home/OS/pocitacove/testovaci_adresar/z/test4.pre_expertov/.-bla/.-bla/'ano'

foreach paths ($something:q)
    set name = "$paths:t"
    @ number = (`grep -Ec "$name" "$paths"`)

    if ($number != 0) then
        echo -n "$paths "
        echo $number
    endif

    @ number = 0
end
Was it helpful?

Solution

Have you tried with grep -F, it assumes input to be string literals and doesn't worry about escape characters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top