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
Help with Fixed width File Parsing sate911 UNIX Desktop for Dummies Questions & Answers 4 05-19-2008 11:18 AM
Changing particular field in fixed width file dsravan Shell Programming and Scripting 4 02-11-2008 06:08 PM
Extracting records with unique fields from a fixed width txt file sitney Shell Programming and Scripting 8 02-10-2008 03:18 AM
Converting a Delimited File to Fixed width file raghavan.aero Shell Programming and Scripting 2 06-06-2007 02:44 PM
Fixed Width file using AWK alok.benjwal UNIX for Dummies Questions & Answers 2 12-05-2005 11:39 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2007
sumeet sumeet is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
adding delimiter to a fixed width file

Hi ,

I have a file :

CSCH74000.00
CSCH74000.00
CSCH74100.00
CSCH74000.00
CSCH74100.00
CSCH74000.00
CSCH74000.00
CSCH74100.00
CSCH74100.00
CSCH74100.00

I have to put a delimiter( say comma) in between after 6th character:

CSCH74,000.00
CSCH74,000.00
CSCH74,100.00
CSCH74,000.00
CSCH74,100.00
CSCH74,000.00
CSCH74,000.00
CSCH74,100.00
CSCH74,100.00
CSCH74,100.00

another scenario is I have:

CSCH72007-03-012007-03-04000.00
CSCH72007-03-052007-03-11000.00
CSCH72007-03-122007-03-18100.00
CSCH742007-03-192007-03-25000.00
CSCH742007-03-262007-03-31100.00
CSCH742007-04-012007-04-01000.00
CSCH742007-04-022007-04-08000.00
CSCH742007-04-092007-04-15100.00
CSCH742007-04-162007-04-22100.00
CSCH742007-04-232007-04-29100.00

I have to put delimiters as following:

CSCH74,2007-03-01,2007-03-04,000.00
CSCH74,2007-03-05,2007-03-11,000.00
CSCH74,2007-03-12,2007-03-18,100.00
CSCH74,2007-03-19,2007-03-25,000.00
CSCH74,2007-03-26,2007-03-31,100.00
CSCH74,2007-04-01,2007-04-01,000.00
CSCH74,2007-04-02,2007-04-08,000.00
CSCH74,2007-04-09,2007-04-15,100.00
CSCH74,2007-04-16,2007-04-22,100.00
CSCH74,2007-04-23,2007-04-29,100.00

Can anyone suggest any idea. I think we will have to use awk to print the file in the file in that specific format.

Thanks
SUmeet
  #2 (permalink)  
Old 03-21-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,507
for 1st eg
Code:
sed -e 's/./&,/6' file
for 2nd eg
Code:
sed -e 's/./&,/6' -e 's/./&,/17' -e 's/./&,/28' file
  #3 (permalink)  
Old 03-21-2007
sumeet sumeet is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
I got it as well but is there any other generic way

awk '{OFS=","};{print substr($1,1,6),substr($1,7,12)}' FILE > sum1

Thanks
Sumeet
Sponsored Links
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 04:22 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