Breaking up of a fixe width line in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Breaking up of a fixe width line in unix
# 1  
Old 12-15-2008
Breaking up of a fixe width line in unix

Hi,

I need some help with breaking up a given line based on 'fixed width' file.

Something like this:

After the breaking up, I need to have this output format...

First line should have the first 134 characters.
Starting from second line, I should have one line every 61 characters of the original line.

Please note that there is only ONE line in the inbound file.

so, lets say I have this line:

Code:
CICS           4                                                         7050                                                         1010     9D103670833                                         1010     9D7006406542


I should have this line broken up into this:

Code:
Line 1: CICS           4                                                         7050                                                         


Line 2: 1010     9D103670833                                         
Line 3: 1010     9D7006406542

I hope I am clear.
# 2  
Old 12-15-2008
Hammer & Screwdriver So, something like the following?

Code:
> cat file114
CICS           4                                                         7050                                                         1010     9D103670833                                         1010     9D7006406542
CICS           5                                                         7050                                                         1010     9D103670833                                         1010     9D7006406542
> awk '{print substr($0,1,134)"\n"substr($0,135,61)"\n"substr($0,196,61)}' file114
CICS           4                                                         7050                                                         
1010     9D103670833                                         
1010     9D7006406542
CICS           5                                                         7050                                                         
1010     9D103670833                                         
1010     9D7006406542

# 3  
Old 12-15-2008
Thank you...

Joey...


Thank you, this is pretty much what I was looking for. Appreciate your help.

Rahul.
# 4  
Old 12-16-2008
Slight change in the answer.

Joey/anybody,

Is there anyway to generically add this to do this indefinitely? because, you are taking 61 character from 135 and 196 columns...how do I write this for the size of the line I wouldn't know about?

Rahul.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

2. Red Hat

How to know full width blade or half width blade?

HI, How do we figure out if the server is half blade server or full blade server? Anything we need to look at to know on this? thanks in advance (9 Replies)
Discussion started by: snchaudhari2
9 Replies

3. Shell Programming and Scripting

UNIX command -Filter rows in fixed width file based on column values

Hi All, I am trying to select the rows in a fixed width file based on values in the columns. I want to select only the rows if column position 3-4 has the value AB I am using cut command to get the column values. Is it possible to check if cut -c3-4 = AB is true then select only that... (2 Replies)
Discussion started by: ashok.k
2 Replies

4. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

5. Shell Programming and Scripting

Remove new line character and add space to convert into fixed width file

I have a file with different record length. The file as to be converted into fixed length by appending spaces at the end of record. The length should be calculated based on the record with maximum length in the file. If the length is less than the max length, the spaces should be appended... (4 Replies)
Discussion started by: Amrutha24
4 Replies

6. Shell Programming and Scripting

'for LINE in $(cat file)' breaking at spaces, not just newlines

Hello. I'm making a (hopefully) simple shell script xml parser that outputs a file I can grep for information. I am writing it because I have yet to find a command line utility that can do this. If you know of one, please just stop now and tell me about it. Even better would be one I can input... (10 Replies)
Discussion started by: natedawg1013
10 Replies

7. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

8. UNIX for Dummies Questions & Answers

printing configuration, line width

Hello, I have to configure printing format under aix 5.3, but don t manage to change size of lines. Thanks if you can help me : --- Printer description : I have a printer "pcltest" using HPJetDirect : hplj-4+ (PCL) I have a queue "qtest" defined on printer hp@pcltest --- Queue... (2 Replies)
Discussion started by: astjen
2 Replies

9. Shell Programming and Scripting

Breaking line

My input file is like USER_WORK.ABC USER_WORK.DEF I want output file like ABC DEF (4 Replies)
Discussion started by: scorp_rahul23
4 Replies

10. UNIX for Dummies Questions & Answers

Command Line width parameter

can someone please tell me how i can increase the number of characters that can be input on the command line? (2 Replies)
Discussion started by: Scoogie
2 Replies
Login or Register to Ask a Question