The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
converting a tabular format data to comma seperated data in KSH Hemamalini UNIX for Dummies Questions & Answers 2 06-16-2008 05:37 AM
extract specific data from xml format file. 60doses Shell Programming and Scripting 7 01-16-2008 03:26 AM
how to number format a data file without using SED? Cactus Jack UNIX for Dummies Questions & Answers 3 01-12-2008 07:47 PM
Check whether a given file is in ASCII format and data is tab-delimited Mandab Shell Programming and Scripting 9 05-03-2007 07:25 PM
write data into a text file in bold format miltony UNIX for Dummies Questions & Answers 1 09-28-2005 08:21 AM

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 08-14-2008
cnilashis cnilashis is offline
Registered User
  
 

Join Date: Apr 2008
Location: Long Island, NY, USA
Posts: 2
Sed to format data in a file

Hi , i need help with formatting a file i am generating which is to be used in mainframe app so the file length has to be 80 for each rows. The file that m able to generate looks like this (consists of two rows only)
Code:
 
E
1006756
1006756
Active
T
 
E
0551055
0551055
Active
T
I want the file to be like:
Code:
 
E10067561006756                Active                  T           
E05510550551055                Active                  T
(the lngth of 3rd fld - 1006756 is 30, so i have 23 space after the number, samewise the length of 4th fld is 30, so i have 24 space after the word "Active". After the word "T", i have 11 more space which is used to be a filler so that we get total 80 as the line size.

How can i ensure this using sed, i have access to shell script.
Thanks in advance for your help.

Last edited by Ygor; 08-15-2008 at 01:22 AM.. Reason: Added code tags
  #2 (permalink)  
Old 08-14-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,400
try this
sed '/./N;s/\n/ /;/./N;s/\n/ /;/./N; s/\n/ /;/./N; s/\n/ /;/^$/d' filename
  #3 (permalink)  
Old 08-15-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Are you sure sed is the right tool for the job?

Code:
awk '{ printf "%s%s%-23s%-30s%s", $1, $2, $3, $4, $5 }' filename
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 02:13 AM.


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