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 06:07 AM
How to ignore incomplete files sentak SUN Solaris 6 02-14-2008 04:03 PM
How to ignore incomplete files sentak Shell Programming and Scripting 6 02-14-2008 02:29 PM
split line when found newline HAA Shell Programming and Scripting 2 11-19-2007 11:34 AM
Join of files is incomplete?! s0460205 Shell Programming and Scripting 7 06-08-2006 04:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-14-2004
ziyi ziyi is offline
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!
  #2 (permalink)  
Old 04-14-2004
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

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

awk 1 infile > outfile
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0