The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
append newline to existing variables finalight Shell Programming and Scripting 1 05-21-2008 02:07 AM
How to ignore incomplete files sentak SUN Solaris 6 02-14-2008 01:03 PM
How to ignore incomplete files sentak Shell Programming and Scripting 6 02-14-2008 11:29 AM
split line when found newline HAA Shell Programming and Scripting 2 11-19-2007 08:34 AM
Join of files is incomplete?! s0460205 Shell Programming and Scripting 7 06-08-2006 12:40 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-14-2004
Registered User
 

Join Date: Apr 2004
Posts: 1
append newline to files with incomplete last line

Hi all,

Is there any way I can check a file for the linefeed character at the end of the file, and append one only if it is missing (ie. Incomplete last line)?

Need to do this because I need to write a script to process files FTP-ed over from various machines, which may or may not be running UNIX. The files are not supposed to have any trailing blank lines after the last line. I also need to compare the number of lines in the file with a corresponding file which contains the number of lines expected in the first file, and process the file only if the numbers are equal.

My problem now is that files created on the Windows platform always have this "Incomplete last line" error when opened with vi after doing a dos2unix operation. This causes wc to count one less line than what is in the file, and the script fails when comparing the number of lines.

I tried using
  echo >> $filename
but while it solves the incomplete last line problem with the Windows-created files, it also appends a new line to the UNIX-created files.

Thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 04-14-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Perhaps use awk...

awk 1 infile > outfile
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0