LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-12-2006, 09:04 AM   #1
bryan.out.there
LQ Newbie
 
Registered: May 2006
Posts: 6

Rep: Reputation: 1
how to insert newlines into a dd-converted ascii file


Hi World,

I have files which I've pulled off of 8mm tape with dd using the conversion to ascii option (from ebcdic) as follows:

dd if=/dev/rmt/$1n of=$file ibs=8k conv=ascii

This works fine except that the file created is not line-terminated correctly and when viewed in nedit for example, the entire file is all in one line.
Nedit allows changing the wrap but it doesn't get it quite the way it should be and doesn't save the changes (hangs) when trying to save large-ish files with the option to ad line-breaks where wrapped.

I've tried changing block sizes and also re-running dd on the file with an unblock and block option to no avail.

Seems to be platform independent (Solaris and cygwin give same results)

Any other ideas much appreciated.
Bryan.
 
Old 09-13-2006, 09:55 AM   #2
soggycornflake
Member
 
Registered: May 2006
Location: England
Distribution: Slackware 10.2, Slamd64
Posts: 249

Rep: Reputation: 31
I know nothing about ebcdic, but according to this, it has carriage return (CR = 0x0d (same as ascii of course)), newline (NL = 0x15), and linefeed (LF, 0x25).

I've no idea which of these characters ebcdic uses as an end-of-line marker, but whatever it is (I assume you know, or can figure it out from the files), you can easily convert it (or them) to the ascii newline that unix uses.

For example, if it uses the NL character (0x15), then

Code:
perl -i -wpe 's/\x15/\n/' <files>
should do it (note that this will do in-place replacement, so you might want to leave out the -i until you're sure it works...).

edit:
Oops, you'll probably need to add the g flag to make perl do a global replacement (i.e. 's/\x15/\n/g'), since there will probably be more than one per "line".

Last edited by soggycornflake; 09-13-2006 at 12:46 PM.
 
Old 09-13-2006, 11:42 PM   #3
bryan.out.there
LQ Newbie
 
Registered: May 2006
Posts: 6

Original Poster
Rep: Reputation: 1
dd - how to determine cbs flag to get newlines correct

Thanks a lot for this reply I'll check it out.

I've made some progress with dd:

dd if=/dev/rmt/$1n of=$file cbs=80 ibs=1024k conv=unblock,aciii

but this doesn't work all the time as tapes are written with different cbs values and seldom is this recorded.
What's also odd is that sometimes you need unblock,ascii and for other files you reverse this to ascii,unblock. Couldn't see this anywhere in man or info.
Changing the cbs (convert bytes size) changes the width (number of characters per line but it's still hit and miss to get it to look as it should. Mostly miss at this stage.
How does one determine the cbs value for data on tape?
I know you can use dd to determine the block size by extracting one block with count=1 and checking its size but don't know how to do this for cbs.

Rgds,
Bryan.
 
1 members found this post helpful.
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to insert characters by ascii code? J_Szucs Linux - General 14 06-17-2017 12:33 PM
Revert ASCII armored file guedellas Linux - Security 1 08-09-2006 05:25 PM
line numbering in ASCII file rohr Programming 4 03-18-2005 09:14 AM
get file contents with newlines into bash variable otoomet Linux - Software 2 01-06-2005 01:23 PM
Displaying a text file in ascii?? bauld Linux - General 4 11-21-2001 07:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:39 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
Open Source Consulting | Domain Registration