how to reformat a file to 80 byte rec length?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to reformat a file to 80 byte rec length?
# 1  
Old 04-19-2006
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  
Old 04-19-2006
It should be conv=block so try that. It's incredible that conv=unblock was close.
# 3  
Old 04-21-2006
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  
Old 04-25-2006
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  
Old 04-25-2006
Code:
fold -w 80 [file]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reformat Header of Variable Length

Dear Forum, I am struggling with reformatting headers in protein sequence files. For the input file each header (lines starting with @) contains and unique ID followed by barcode (bc) information (a,b,c,d,f,g). The header is of variable length and some barcodes are missing or extra for certain... (4 Replies)
Discussion started by: GDC
4 Replies

2. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

3. Shell Programming and Scripting

Reformat a file

I have a csv file with 11 columns. The first columns contains the User Id. One User id can have multiple sub Id. The value of Sub Id is in column 10. 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969, ,US, ,96761 ,15 ,seg_id 100026,captjason@hawaii.rr.com ,jason ,wolford ,1/16/1969,... (3 Replies)
Discussion started by: r_t_1601
3 Replies

4. Shell Programming and Scripting

Please help me reformat this file

I am working with a file of the form; 4256 7726 1 6525 716 1 7626 0838 1 8726 7623 2 8625 1563 2 1662 2628 3 1551 3552 3 1542 7984 ... (3 Replies)
Discussion started by: digipak
3 Replies

5. Shell Programming and Scripting

Remove a byte(Last byte from the last line)

Hi All Can anyone please suggest me how to remove the last byte from a falt file .This is from the last line's last BYTE. Please suggest me something. Thank's and regards Vinay (1 Reply)
Discussion started by: vinayrao
1 Replies

6. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

7. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

8. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

9. Shell Programming and Scripting

Setting local vars from a header rec in another file?

Hey guys, We are going to be receiving files containing header information. This will be 1 line of code in each file containing the following format: 20050719hhmmsssfgr00310000537000000000000000 My question is...How can I pull parts of the header info and set it to vars in my shell. I... (4 Replies)
Discussion started by: ecupirate1998
4 Replies

10. Shell Programming and Scripting

reformat the file

Hi all, I ran into this problem, hope you can help I have a text file like this: Spriden ID First Name Last Name Term Code Detail Code Amount Trans Date Description ... (3 Replies)
Discussion started by: CamTu
3 Replies
Login or Register to Ask a Question