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
Breaking line scorp_rahul23 Shell Programming and Scripting 4 09-18-2008 08:45 AM
text width sharanbr UNIX for Dummies Questions & Answers 2 06-09-2008 06:02 AM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 04:34 PM
User ID width thmnetwork Linux 4 04-09-2005 01:50 PM
Command Line width parameter Scoogie UNIX for Dummies Questions & Answers 2 02-08-2002 05:04 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 12-15-2008
rputtagunta rputtagunta is offline
Registered User
  
 

Join Date: Apr 2007
Location: Texas, USA
Posts: 5
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 (permalink)  
Old 12-15-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink 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 (permalink)  
Old 12-15-2008
rputtagunta rputtagunta is offline
Registered User
  
 

Join Date: Apr 2007
Location: Texas, USA
Posts: 5
Thank you...

Joey...


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

Rahul.
  #4 (permalink)  
Old 12-16-2008
rputtagunta rputtagunta is offline
Registered User
  
 

Join Date: Apr 2007
Location: Texas, USA
Posts: 5
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.
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 01:10 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