Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with tail command in bash script in Ubuntu Server 10.04 with tfiles with fewer than 10 lines 1

Status
Not open for further replies.

NewtownGuy

Technical User
Jul 27, 2007
146
US
I have a bash script that is supposed to process the ten last lines, or fewer in files with fewer than ten lines, of a text file. I use 'tail' to read these lines into a new text file, which I then read into an array. There's a problem when the file being read has fewer than ten lines. The problem is that I always get ten lines regardless of how many lines are in files with fewer than ten lines. The first lines are correct, but the balance of the ten lines comes from other files. The tail command works fine from the command line.

Why do I always get ten lines when the script runs and how do I get no more lines than are in the file ?

Thank you in advance for your help.

 
Well, I doubt it's the tail command that's at fault... more likely the scripting around it. Can we see the relevant parts?

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
I found a dumb error in the surrounding code. Sigh...

 
Ah, the ol' "dumb error in the surrounding code" bug again, 99! :)

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top