![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#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! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Perhaps use awk...
awk 1 infile > outfile |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|