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
What the command to find out the record length of a fixed length file? tranq01 UNIX for Dummies Questions & Answers 9 12-04-2008 04:04 PM
zero byte file dsdev_123 AIX 2 03-20-2008 10:50 AM
0 byte file with no name???? miltonkeynesguy Shell Programming and Scripting 5 08-17-2007 09:01 AM
Reformat Crontab file alnita Shell Programming and Scripting 1 04-11-2007 03:28 AM
reformat the file CamTu Shell Programming and Scripting 3 03-09-2005 05:01 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-19-2006
cmgarcia cmgarcia is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 1
how to reformat a file to 80 byte rec length?

I have a variable length file that needs to be reformatted to 80 byte reclen before I ftp it to a customer. What is the best way to do this? I tried using dd if=inputfile of=outputfile conv=noblock cbs=80, and it almost gives me what I need. The output file needs to be 80-byte records, and the last record needs to be padded to 80 bytes. I can't get the last record padding with dd. BTW, I'm on AIX 5.2.

Can I use an AWK for this?
  #2 (permalink)  
Old 04-19-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,123
It should be conv=block so try that. It's incredible that conv=unblock was close.
  #3 (permalink)  
Old 04-21-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Quote:
Originally Posted by cmgarcia
I have a variable length file that needs to be reformatted to 80 byte reclen before I ftp it to a customer. What is the best way to do this? I tried using dd if=inputfile of=outputfile conv=noblock cbs=80, and it almost gives me what I need. The output file needs to be 80-byte records, and the last record needs to be padded to 80 bytes. I can't get the last record padding with dd. BTW, I'm on AIX 5.2.

Can I use an AWK for this?
You could try something like:

Code:
awk '{printf("%-'80's\r\n",$0)}' [file] > [newfile]
The "\r" and "\n" terminate each record (line) with carriage-return and linefeed. If you only need linefeeds, just omit the "\r". This won't work if you have tabs in the file, however.

Edit: This is for HP-UX.

Edit2: This also assumes that your record lengths are currently less than or equal to 80. That awk command won't help if you have record lengths greater than 80 -- if you do, they would need to be truncated or folded first.

Last edited by Glenn Arndt; 04-21-2006 at 12:46 PM..
  #4 (permalink)  
Old 04-25-2006
merliech merliech is offline
Registered User
  
 

Join Date: Apr 2006
Location: Suburbs of IL
Posts: 3
How to truncate/fold data so that it can be formatted to 80-byte file?

I have a unix file that needs to be formatted to an 80-byte file. We have an HP-UX system, so I think the last Awk example will work. Since my file is greater than 80-bytes in length, can someone explain how to "fold" the file?

Thank you!

Melissa
  #5 (permalink)  
Old 04-25-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Code:
fold -w 80 [file]
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 06:18 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