Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-07-2009
Registered User
 

Join Date: Apr 2009
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
Awk not working due to missing new line character at last line of file

Hi,

My awk program is failing. I figured out using command

Code:
od -c filename

that the last line of the file doesnt end with a new line character.

Mine is an automated process because of this data is missing.
How do i handle this?

I want to append new line character at the end of last line in file if it is missing.
i tried doing this.

Code:
echo ,,,, >> file

thinking this will add a line the file.


Quote:
File
ABC,ABC,ABC,,,,
Instead this is appending to the last field of the last line.

I want
Quote:
File
ABC,ABC,ABC\n
where \n is new line character

Help is appreciated
Sponsored Links
    #2  
Old 05-07-2009
TonyFullerMalv's Avatar
Registered User
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 1,032
Thanks: 0
Thanked 6 Times in 6 Posts

Code:
echo "" >> filename

Will add a new line character to the end of the file.


Code:
$ echo fred > fred
$ od -bc fred
0000000 146 162 145 144 012
          f   r   e   d  \n
0000005
$ echo "" >> fred
$ od -bc fred
0000000 146 162 145 144 012 012
          f   r   e   d  \n  \n
0000006
$

Sponsored Links
    #3  
Old 05-07-2009
Registered User
 

Join Date: Apr 2009
Posts: 211
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by TonyFullerMalv View Post
Code:
echo "" >> filename

Will add a new line character to the end of the file.


Code:
$ echo fred > fred
$ od -bc fred
0000000 146 162 145 144 012
          f   r   e   d  \n
0000005
$ echo "" >> fred
$ od -bc fred
0000000 146 162 145 144 012 012
          f   r   e   d  \n  \n
0000006
$

Thankyou TonyFullerMalv
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
append a character at end of each line of a file muaz Shell Programming and Scripting 4 06-25-2008 07:48 AM
How to add new line character at the end of a file DebianJ UNIX for Dummies Questions & Answers 5 05-07-2008 03:22 PM
Need to serach if a new line character exists on the last line in a file sunilbm78 UNIX for Dummies Questions & Answers 10 02-29-2008 01:15 PM
delete a line based on first character of the line borncrazy UNIX for Dummies Questions & Answers 2 12-06-2005 02:27 PM
How would I replace the 9th character of every line in a file? LordJezo Shell Programming and Scripting 5 09-01-2004 11:51 AM



All times are GMT -4. The time now is 12:42 AM.