Email: bknpk@hotmail.com Phone: +972-54-7649119
V

 

ASIC/FPGA Design and Verification Out Source Services

Recursive Search

A simple -one line- script to recursively search files based on find and grep.
The script was tested on debian bash.

  1. First I put an alias to easily invoke the script. This is done by placing the following line in your ~/.bash_aliases file:
  2. alias Fg="~/bin/fg.unx"

  3. Next comes the simple script:
  4. #!/bin/bash

    if [ "$#" -eq 0 ]
    then
      echo "example fg \"*.html\" n \"courier\""
      echo "days ago for file lookup"
      echo "example fg \"*.html\" n \"courier\" -30"
      exit
    fi

    echo "start ------"
    if [ "$4" = "" ] ; then
      find . -name "$1" -exec grep -$2 "$3" /dev/null {} \;
    else
      find "$4" -name "$1" -exec grep -$2 "$3" /dev/null {} \; | gvim - +/"$3"
    fi

    Note: the parameters n and l are the ones given to grep command.
    Also note: you can, optionally, specify a starting directory (the default is . pwd).


  5. Another way of doing the same is from a bash script
    #!/bin/bash

    for i in $(find . -name "*.e"); do perl ~/bin/cmp_diff.pl "$i" "$1"/; done
    for i in $(find . -name "*.vhd"); do perl ~/bin/cmp_diff.pl "$i" "$1"/; done

    Note: that in some cases it is simpler to use diff with recursive option:
    diff -qr dir_1 dir_2

  6. Or simply do a one command using for, find and grep - all combined together for a powerful search and grep command:

    for f in `find . -type f`; do grep -l "list.*Check" $f; done
    for f in `find . -name "*.e"`; do grep -l "list.*Check" $f; done

    Sometimes you want to do it without a script, but rather from the command line.
    On bash you would do:
    for x in `ls` <cr>
    do <cr>
    echo $x <cr>
    done <cr>

    On tcsh you would do:
    foreach x (dir_1 dir_2) <cr>
    echo $x <cr>
    svn exp $x <cr>
    end <cr>

    To extract a filed from list in file and sort it:
    foreach x ( `cat /tmp/debug.txt | awk '{print $3}' | sort -u ` )
    ...


    If you run find from multiple terminals, with a unique search pattern, you can save the results in different files:

    x=Fp_$$; date > $x;for f in `find . -name "*.e"`; do grep "list.*byte.*;" $f >> $x && echo "File="$f >> $x; done

    Note: each file has a unique name, which starts with Fp_ and concatenated with the shell process ID ($$).


Please let me know what you think on my site.

 


Contact me now at:

  ...


I would be happy to offer my services. Call ASAP !


Home

SD slave with Samsung flash (vhdl project).

A simple c-code program to read a memory array from verilog RTL, using VPI.






Search This Site


Feedback This Site




new pages on this site