0

My document.tex where I want to get the list of files, and grep those files with the term gastric

\subimport{}{1.2_protocal_answers.tex}
\subimport{}{2_protocol_answers.tex}
  • 1.2_protocal_answers.tex content: this is a gastric juice lorem content
  • 2_protocol_answers.tex content: this is a second gastric\n test file

My .pdf output is broken, but I need to search the contents in the material. My Directory is too massive to do it for all, which can be done with Geany's Find in Files. I would like to do dependent search on the files that are imported in the file. Attempts

  • Pseudocode where I cannot get the list of files in the .tex document

    find ./document.tex -type f -exec \
        grep -E '\subimport{[A-Za-z1-9_-]*} {} \; 
    # TODO search the list of files with the word `gastric`
    
  • Any IDE approach? My favorite IDE uses grep internally so I think find-grep approach is the most appropriate here.

System: Ubuntu 16.04, 64 bit
Grep: grep (GNU grep) 2.25
Find: find (GNU findutils) 4.7.0-git
Hardware: Macbook Air 2013-mid
Linux kernel: 4.6

1
  • @Theophrastus As a one-liner, it could be run inside any IDE using grep as their internal machine. But I think you are right. It can be done in two steps. Please, consider an answer so I can better understand your proposal. Jun 15, 2016 at 17:26

3 Answers 3

1

Edited as the user needs:

   cat document.tex | cut -d'{' -f3 | cut -d'}' -f1 | while read file
         grep -i 'gastric' "$file" &>/dev/null && echo "$file contains gastric"
   done 
4
  • I get blank output when running your command on document.tex. Those links are relative to $PWD. Should it be considered here too? Those two files are at ./ i.e. the same location where I run the command and where the document.tex locates. What do you get as an output? Jun 15, 2016 at 20:38
  • I am understanding that you want to find files containing the grep rule, how document.tex is related with this ? And what you mean with this: # TODO search the list of files with the word gastric, grep -R 'gastric' will search all the files in the directory you are with the world 'gastric', i really not getting what you are trying to do. Can be more specific? Jun 15, 2016 at 20:46
  • The document.tex's content is those two lines. Grep must first find those files, and then apply search in the content of the files in the list. I created the two dummy files in the body which have now the test content. I want to grep the content of the file list (here two dummy files). Jun 15, 2016 at 20:48
  • 1
    Oh now i understand, i am righting your answer right now. Jun 15, 2016 at 20:51
1
perl -l0 -ne 'print for /\\subimport\{\}\{(.*?)\}/g' file.tex

Would print the filenames inside those \subimport{}{...} functions NUL-delimited.

You can pipe that to xargs -0 grep -l gastric -- to find which of those files contain gastric.

1
0

In the end, I use the search in directory by the script here with a redirection to Vim. It would be great to get something like that work in Geany IDE directly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .