Formatting File having big single line into 95 Char Per Line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting File having big single line into 95 Char Per Line
# 1  
Old 10-31-2012
Formatting File having big single line into 95 Char Per Line

Hi All,

I have 4 big files which contains one big line containing formatted character records, I need to format each file in such way that each File will have 95 Characters per line. Last line of each file will have newline character at end.

Before:-
File Name:- File1.dat
Code:
102 121340560 1210001341210300400A094101ABCDEFG ABCDEFGH SEDABCD ABCDIFARION RFTPERSR        1234ABCDCARPABCDEF                   0366130207ASDFGYHUIO11011212110130610710034042404246222910750809020101142       0000026950329075001      ABCRFTYU DERTF           0071003402508271820000000100291075080000000000000000000269500366

After:-
Code:
102 121340560 1210001341210300400A094101ABCDEFG ABCDEFGH SEDABCD ABCDIFARION RFTPERSR        
1234ABCDCARPABCDEF                   0366130207ASDFGYHUIO110112121101306107100340424042462229
10750809020101142       0000026950329075001      ABCRFTYU DERTF           0071003402508271820
000000100291075080000000000000000000269500366

Similar remaining file will be formatted in same fashion.
Thanks in advance guys.
-LanceSunny
# 2  
Old 10-31-2012
Try:
Code:
 dd if=<infilename> of=<outfilename> cbs=95 conv=unblock

This User Gave Thanks to vbe For This Post:
# 3  
Old 10-31-2012
vbe Thanks for you help regarding this.
I ma sorry but when I execute this command I get either file not found or 0+0 records in & o bytes copied.

Code:
dd if=<File1.dat> of=<File1Final.dat> cbs=95 conv=unblock

Here File1 is the file name
File1Final.dat trying to copy finalize contents to new file.
Thanks,
Lance

Last edited by lancesunny; 10-31-2012 at 04:43 PM..
# 4  
Old 10-31-2012
Remove the "<>" around the file names

Code:
dd if=File1.dat of=File1Final.dat cbs=95 conv=unblock

This User Gave Thanks to scottaazz For This Post:
# 5  
Old 10-31-2012
Code:
fold -w95 file

These 2 Users Gave Thanks to Scrutinizer For This Post:
# 6  
Old 10-31-2012
Thanks vbe, scottaazz & Scrutinizer. All your solution worked.
Can you guys please tell me what I need to do in order to add new line after only last line in the file?

Here are the command which worked:-
Code:
fold -w95 fileName

OR
Code:
dd if=FileName.dat of=NewFile.dat cbs=95 conv=unblock

Thanks,
Lance
# 7  
Old 10-31-2012
Quote:
Originally Posted by lancesunny
I need to format each file in such way that each File will have 95 Characters per line.
Quote:
Originally Posted by lancesunny
Code:
dd if=FileName.dat of=NewFile.dat cbs=95 conv=unblock

dd's unblock conversion yields variable length records/lines. If, as you say, the result must consist of 95 character lines, you cannot use that dd approach, because it will strip trailing space characters from a 95 character block and leave something shorter.

Regards,
Alister
This User Gave Thanks to alister For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues formatting output of two commands in a single line.

I wish to generate output of two commands in the same line separated by a single white-space. Below is my command and output in the same line. ls -ltr fname1.out | awk '{$2=$4=$5=x; print}' | tr '\n' '\t' | tr -s ' '; cksum<fname1.out | cut -d' ' -f1 Output: -rw-r--r--. root Aug 26 16:57... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Beginners Questions & Answers

Output to file print as single line, not separate line

example of problem: when I echo "$e" >> /home/cogiz/file.txt result prints to file as:AA BB CC I need it to save to file as this:AA BB CC I know it's probably something really simple but any help would be greatly appreciated. Thank You. Cogiz (7 Replies)
Discussion started by: cogiz
7 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

How to separate one line to mutiple line based on one char?

Hi Gurus, I need separate one file which is one huge line to mutiple line. file like abcd # bcd # def # fge # ged I want to get abcd bcd def fge ged Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

5. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

6. UNIX for Dummies Questions & Answers

Remove First Char from Line in File Only if it's a comma

I have a file, I need to remove the first character of each line, but only if it's a comma. I don't want to delete any other commas in each line. Trying cat or sed but I really don't know them very well, would love some help. This removes the first comma, but it removes the first comma no... (6 Replies)
Discussion started by: Cynthia
6 Replies

7. Shell Programming and Scripting

awk concatenate every line of a file in a single line

I have several hundreds of tiny files which need to be concatenated into one single line and all those in a single file. Some files have several blank lines. Tried to use this script but failed on it. awk 'END { print r } r && !/^/ { print FILENAME, r; r = "" }{ r = r ? r $0 : $0 }' *.txt... (8 Replies)
Discussion started by: sdf
8 Replies

8. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

9. Shell Programming and Scripting

how first char in odd line and second char in even line

Hi I m having ifconfig -a o/p like sbanlab1:ksh# ifconfig -a | egrep "flags|inet" | awk -F' ' '{print $1,$2}' lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> inet 127.0.0.1 bge0:... (1 Reply)
Discussion started by: tarunn.dubeyy
1 Replies

10. Shell Programming and Scripting

Formatting a text file to get data in exact line by line

I have my data something like this SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430693 07/01/2009 05:16:40 FR SERIAL FIRSTOCCURRENCE NETPROTOCOL 1947430746 07/01/2009 05:18:05 FR I want the output as follows.... (1 Reply)
Discussion started by: rdhanek
1 Replies
Login or Register to Ask a Question