LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 08-01-2011, 06:09 PM   #1
Fliggerty
LQ Newbie
 
Registered: Dec 2009
Posts: 6

Rep: Reputation: 0
Finding the right file, with only a line and column number


I tried to come up with a thread title that was specific without being too long or cryptic. Don't think I succeeded.

In my PHP error log I keep getting this error over and over again:

Code:
EntityRef: expecting ';' at line 565, column 81
It's very odd to me that it doesn't contain any sort of stack trace or file info. I know which of my virtual hosts and therefore which directory it's coming from, and it's happened now on half a dozen different servers that this site has lived on.

So obviously I'm trying to track it down and add the missing ';' to the right file. This directory has dozens of sub-directories and hundreds of files though.

This is the best I've managed to come up with so far:

Code:
find . -type f -iname "*.php" -print -exec awk 'NR==565' {} \;
(I've run it both with and without the -iname filter.)

So I get a very large list of files, and some of them display the contents of line 565 after them. I've checked through a number of them there, but haven't found the culprit.

These are my questions:
  1. Is it possible to limit my "find" command to only files that have at least 565 lines?
  2. Is it possible to have it only print matches from line 565 that has at least 81 columns?
  3. How would I modify that to print perhaps 5 lines on either side (in case the error reporting is pulling a slightly different line.)
  4. Does anyone have any other suggestions on how I might track this thing down?

Thanks!
 
Old 08-01-2011, 06:42 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi,

try this for a start:
Code:
find /path/to/dir -type f -name 'filename' -exec awk '{if (NR==565){if (length >= 81){print FILENAME": " $0}}}' {} \;
Notice, that 'find' does no longer print the filename. This is done by awk now only if the appropriate conditions are met.

Last edited by crts; 08-02-2011 at 11:15 AM.
 
Old 08-01-2011, 06:58 PM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
I have been thinking about the context issue. The fastest solution would be to implement this with the 'awk' statement. This is a bit complicated though and I do not have the time right now. As a quick 'n' dirty solution you could pipe the result to sed:
Code:
find . -type f -name 'filename' -exec awk '{if (NR==565){if (length >= 81){print FILENAME}}}' {} \; | xargs sed -n '560,570 p'
This will only print the filename if the conditions are met and sed is responsible for the printing. Notice, that xargs is necessary here.

Last edited by crts; 08-02-2011 at 11:16 AM.
 
Old 08-01-2011, 07:27 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Presumably 'EntityRef' is a var? You should check for files containing that, at least 565 lines long
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Help with awk finding line number and deleteing text puth Programming 1 02-24-2010 12:29 PM
Find Number of column in a file Swapna173 Linux - Newbie 3 06-04-2008 02:29 AM
sed / awk command to print line number as column? johnpaulodonnell Linux - Newbie 2 01-22-2007 08:07 AM
file processing -- remove the first column of each line George2 Programming 7 11-19-2006 10:15 AM
help on finding the number that has max occurrences in a column [sql query] zeppelin Programming 6 06-15-2004 02:41 PM


All times are GMT -5. The time now is 05:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration