LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices



Reply
 
Search this Thread
Old 09-11-2006, 04:28 PM   #1
amh06
LQ Newbie
 
Registered: Sep 2006
Posts: 3

Rep: Reputation: 0
Need to Insert Newline Char


I have a large file that's come through without newlines. When I run a word count on it (wc) it lists 0 lines. I know it's got the data there - I can see it. But I need to break it up into individual records.

The record length is 241 characters and there should be over 16 million records. I first tried using the command 'fold' and it seemed to work, but when I 'wc' the resulting file it comes up with 1 less record than what it should come up with. And when I divide the total number of bytes by what the record length should be with the newline, I don't come up with and even number...so I know it's missing something somewhere (but only 1 byte - jeez!).

Any suggestions? Thanks, in advance for your help!
 
Old 09-11-2006, 05:48 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
If it's only 1 record less than it should be, could it be that the very last line doesn't end with a newline character?
 
Old 09-11-2006, 09:45 PM   #3
amh06
LQ Newbie
 
Registered: Sep 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gilead
If it's only 1 record less than it should be, could it be that the very last line doesn't end with a newline character?
I think that is the case. Is there a way to put one after the last line? I'd like the record count to match the total number of records and right now it's showing up as 1 shy of the total.
 
Old 09-11-2006, 10:31 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
It's very clunky, but if all you're missing is the final newline (1 byte), then the following works on my box:
Code:
echo -e >> outputfile
The result is a blank line at the end of the file and a filesize that is increased by 1 byte - but it's not an elegant way to solve the problem.
 
Old 09-12-2006, 09:34 AM   #5
amh06
LQ Newbie
 
Registered: Sep 2006
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you, Steve. That seems to have done the trick.

I appreciate your help! ~Anne
 
Old 09-12-2006, 03:10 PM   #6
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
No problem - I'm glad it's giving the results you wanted
 
Old 09-15-2006, 03:35 AM   #7
stany001
LQ Newbie
 
Registered: Mar 2004
Location: France
Distribution: Slackware & RHEL 6.5
Posts: 7

Rep: Reputation: 0
You can use fold witch insert a newline caracter at 80 (use fold -w 132 toto.txt > toto2.txt if you want to cut at 132 char.)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed: insert a newline. Why does not it work? J_Szucs Linux - Software 4 03-19-2014 02:28 PM
invalid conversion from `const char*' to `char*' deepinlife Programming 22 08-05-2006 11:49 AM
If I get invalid conversion from `const char*' to `char' what should I be lookin for? RHLinuxGUY Programming 5 03-12-2006 11:35 PM
invalid conversion from `char' to `const char* bru Programming 6 05-09-2004 04:07 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 05:09 AM


All times are GMT -5. The time now is 02:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration