The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

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 02:15 PM
delete a line based on first character of the line borncrazy UNIX for Dummies Questions & Answers 2 12-06-2005 03: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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
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
  #2 (permalink)  
Old 05-07-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 730
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
$
  #3 (permalink)  
Old 05-07-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
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
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 05:34 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