0

I have a website that is giving me all sorts of errors, I've ran a recursive script to check for BOM headers.. but how would I do the same thing to find carriage returns and line feeds at the end of a file?

I want to check over my codebase to make sure there aren't any files with extra lines hanging out

Justin
  • 367
  • 1
  • 5
  • 15

1 Answers1

1

i guess you want to check (without remove/replace) the empty lines at the end of a file.

you can try :

 awk '{a=$0;}END{if(!a)print FILENAME}' file

this will print the file name out if there is at least one empty line at the end of the file.

for Recursion, you could use find ... |xargs awk '...'

updated

ok, I made an example, so that you could test:

find . -iname "*.php"|xargs -n1 awk '{a=$0;}END{if(!a)print FILENAME}'

the above line will check all php files recursively based on your current directory, if there is at least one empty line at the end of a php file, print the filename.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • Ok trying to get this. find '\x0' | xargs awk '{a=$0;}END{if(!a)print FILENAME}' – Justin Oct 19 '11 at 09:23
  • @Justin what did you mean? what's `find '\x0'?` – Kent Oct 19 '11 at 09:25
  • Hm I thought \x0 would be perhaps the string to search for http://code.cside.com/3rdpage/us/newLine.html – Justin Oct 19 '11 at 09:28
  • See, http://stackoverflow.com/questions/204765/elegant-way-to-search-for-utf-8-files-with-bom had a snippit to find byte order mark chars in files. I thought the patterns might be similar – Justin Oct 19 '11 at 09:30
  • @Justin see my updated answer, there is an example that you can try out. – Kent Oct 19 '11 at 09:31
  • Yep that did the trick. Thanks.. Hope this helps track down the bug. – Justin Oct 19 '11 at 09:34