### Did you dream of something like this?
open (D_I, "Input.dat") or die "Not found" ; open (D_O, ">Output.dat") or die "Cannot write"; while(<D_I>) { chomp; m'(.{2})(.{7})(.{9})(.{10})([^ ]*)([^,]*),?(?:([^,]*),?)?(.*)'g; printf "%-3s %-8s %-11s %-11s %-11s %-12s %-12s %-12s %-12s \n", $1, $2, $3, $4, $5, $6, $7, $8; printf D_O "%-3s %-8s %-11s %-11s %-11s %-12s %-12s %-12s %-12s \n", $1, $2, $3, $4, $5, $6, $7, $8; } ## What is captured within those (....) in the m' ... ' -line ## is given back as $1, $2, ... . ## Adjust those numbers {..} according to your needs. ## To have the result really tab seperated change the printf line: ## fill in \t instead of blanks in the " ..... " -part. ## ## HTH, Detlef "Mohanty, Debi (MED, TCS)" wrote: > Hi, > I am working on to format a text file in to a tabseparated text file. My > programm is as below ...... > > open (F,"<Input.dat"); > binmode F; > @n=(<F>); > close F; > # READ THE WHOLE FILE > $file=join ("",@n); > # SPLIT THE FILE INTO SEPERATE RECORDS > @records=split(/\r/,$file); > print @records."\n"; > @section=(); > > for ($n=0; $n<@records; $n++){ > $section [$n] =(split /\n/,$records[$n],2)[1]; > $sectionA[$n] = substr($section[$n], 1,7); > print $n.$sectionA[$n]."\n"; > $sectionI[$n] = substr($section[$n], 8,2); > if($sectionI[$n] == 01){$sectionI[$n] = 20;} > elsif ($sectionI[$n] == 00){$sectionI[$n] = 19;} > $sectionK[$n] = substr($section[$n], 10,6); > $sectionB[$n] = $sectionI[$n].$sectionK[$n]; > $sectionC[$n] = substr($section[$n], 16,8); > $sectionD[$n] = substr($section[$n], 24,4); > $sectionE[$n] = substr($section[$n], 28,1); > $sectionF[$n] = substr($section[$n], 29,8); > $sectionG[$n] = substr($section[$n], 37,20); > $sectionH[$n] = substr($section[$n], 57,52); > } > > # PRINT TO THE OUTPUT FILE > open (O,">output.txt"); > for ($n=0; $n<@records; $n++){ > print O $sectionA[$n]." "; > print O $sectionB[$n]." "; > print O $sectionC[$n]." "; > print O $sectionD[$n]." "; > print O $sectionE[$n]." "; > print O $sectionF[$n]." "; > print O $sectionG[$n]." "; > print O $sectionH[$n]."\r"; > } > close F; > > And My Input.dat (Inputfile is): - > > 0102690001020628000928490001Hms03638 LaRosa, Brian added > 0102690001020628000928490002Hms03638 LaRosa, Brian STATUS from INIT to > NEW > 0102690001020628001545480001HMS00169 > BERTAGNOLLI,MILTON,KGENERAL-DISTRIBUTION from N to Y > 0102690001020628001545480002HMS00169 BERTAGNOLLI,MILTON,KRESP-PARTY: > BERTAGNOLLI/KAKIZAWA > 0102690001020628001545480003HMS00169 BERTAGNOLLI,MILTON,KSTATUS from NEW > to SDEF > 0102690001020628001545540001HMS00169 BERTAGNOLLI,MILTON,Kupdated > 0102690001020628001547310001HMS00169 BERTAGNOLLI,MILTON,KNOTE was ADDED > 0102690001020628001547310002HMS00169 BERTAGNOLLI,MILTON,Kupdated > 0102690001020701000348450001HY2060 KIDOKORO,MIYUKI STATUS from SDEF to > EVAL > 0102690001020701000348500001HY2060 KIDOKORO,MIYUKI updated > 0102690101020628000928560001Hms03638 LaRosa, Brian added > 0102690101020628000928560002Hms03638 LaRosa, Brian STATUS from INIT to > NEW > 0102690101020628001546470001HMS00169 > BERTAGNOLLI,MILTON,KGENERAL-DISTRIBUTION from N to Y > 0102690101020628001546470002HMS00169 BERTAGNOLLI,MILTON,KRESP-PARTY: > BERTAGNOLLI/BERTAGNOLLI > 0102690101020628001546470003HMS00169 BERTAGNOLLI,MILTON,KSTATUS from NEW > to SDEF > 0102690101020628001546530001HMS00169 BERTAGNOLLI,MILTON,Kupdated > 0102690101020628001548000001HMS00169 BERTAGNOLLI,MILTON,KNOTE was ADDED > 0102690101020628001548000002HMS00169 BERTAGNOLLI,MILTON,Kupdated > 0102690101020703001045220001HMS00169 BERTAGNOLLI,MILTON,KSTATUS from > SDEF to EVAL > 0102690101020703001045280001HMS00169 BERTAGNOLLI,MILTON,Kupdated > 0102690101020719001709280001HMS00169 BERTAGNOLLI,MILTON,Kupdated > 0102690201020628000934110001HMSY0129 WATANABE,MINORU > GENERAL-DISTRIBUTION from to N > 0102690201020628000934110002HMSY0129 WATANABE,MINORU STATUS from INIT to > NEW > 0102690201020628000934110003HMSY0129 WATANABE,MINORU added > > While in the output I am able to get the file in the tabseparated format > but by first line of the Output is missing. Please help me on this > issue....... Where I am doing the things in a wrong way. > > Thanks&Regards > Debi