Search code examples
shellcommand-linegrepack

Loop through list of files and ack sourcecode to see if files are still used


I have a txt file with loads of old jquery plugin filenames, each on a new line. Ideally, I would be able to loop over this list of filenames, and ack in my source code to find which files still use these libraries while at the same time saying how often. It would help if they outputted into a TSV.

list=file_read(list_of_files.txt);
for (i in list) {
  print "\r\n"+i+"\r\n\t";
  ack -Hclw i
}

The ideal output would look like:

jquery.easing.1.3.js
    file1.js:2
    file5.js:5
    file7.js:2
jquery.form.js
    file1.js:1
jquery.metadata.js
    file1.js:1
    file1.js:1
jquery.pajinate.js
    file1.js:2
    file3.js:2
jquery.tooltip.js
    file3.js:5
jquery.tzCheckbox.js
    file1.js:4
    file4.js:2
    file8.js:1

Thanks a lot guys! I can do this in a script in php, but can't figure it out all in ack. I am pretty sure ack is capable of doing this, but have come up dry after going over the manual.


Solution

  • Maybe you're looking for this:

    while read plugin; do
        echo $plugin:
        ack -Hclw $plugin /path/to/source | sed -e 's/^/    /'
    done < list_of_files.txt