fork download
  1. #!/bin/bash
  2. awk -v msg='new File() Found on line ' '
  3. BEGIN {print ARGV[1], "(Filename)"}
  4. {
  5. while(match($0, /new[[:blank:]]+File\(\)/)) {
  6. print msg NR
  7. ++n
  8. $0 = substr($0, RSTART+RLENGTH)
  9. }
  10. }
  11. /new[[:blank:]]*$/ {
  12. p = NR
  13. next
  14. }
  15. p && NF {
  16. if (/^[[:blank:]]*File\(\)/) {
  17. print msg p, "&", NR
  18. ++n
  19. }
  20. p = 0
  21. }
  22. END {
  23. print n, "(number of occurrences of new File() pattern)"
  24. }'
Success #stdin #stdout 0.01s 5300KB
stdin
    new
    File()
    new File()
    new
    
    
    
    File()
    File() new
    new File() test new File()
stdout
 (Filename)
new File() Found on line 1 & 2
new File() Found on line 3
new File() Found on line 4 & 8
new File() Found on line 10
new File() Found on line 10
5 (number of occurrences of new File() pattern)