in reply to Re: Parse for a name after a keyword search in all the files, given directory as input
in thread Parse for a name after a keyword search in all the files, given directory as input

What I intend to do is, There is a directory, consisting of 10 files in .v format; I feed in the path for directory in command line and my code has to open all the files in the directory, and look for the word modulekeyword present at the starting of any line in the entire file for all the 10 files, and it should print the word next to moduleconsidered as keyword one in each line. As my .v file has multiple 'module' keywords.

Ex : file.v
Line No.2> module GATES(clock,variable); .... .... Line No.100> module FF(op, ip,);

Output expected- GATES in 1st line FF in 2nd line

  • Comment on Re^2: Parse for a name after a keyword search in all the files, given directory as input
  • Download Code

Replies are listed 'Best First'.
Re^3: Parse for a name after a keyword search in all the files, given directory as input
by hippo (Archbishop) on Feb 17, 2017 at 09:07 UTC

    So now we know in a little more detail what you want your script to do. Unfortunately you still have not said in what way it is going wrong.

    Here then are a few suggestions.

    1. Read, understand and implement at least the first 2 steps of the Basic Debugging Checklist. Do this now, before anything else.
    2. Test to see if you are actually looping over all files in the directory. At the very least print a count of all the files you have tested by the end of the script.
    3. Test your regex (which we now know is wrong). A simple perlish grep will do: perl -ne '/^module / and print' somedir/filename.v and then modify the regex until it extracts what you want.
    4. If you still can't get the required output then post back here stating precisely in what way your code fails and providing an SSCCE

    Happy debugging!