Computing.Net > Forums > Unix > how to get fixed width file in unix

how to get fixed width file in unix

Reply to Message Icon

Original Message
Name: trichyselva
Date: March 2, 2007 at 00:54:19 Pacific
Subject: how to get fixed width file in unix
OS: xin xp
CPU/Ram: p4
Model/Manufacturer: pentium
Comment:

i have a file in unix in which datas are like this

07 01 abc data entry Z3 data entry ASSISTANT Z3 39
08 01 POD peadiatrist Z4 POD PeDIATRY Z4 67
01 operator specialist 00 operator UNSPECIFIED A0 00
02 OLD NPA SPECIALTY 01 GP GENERAL PRACTICE C5 01

i want the datas to be tilde delimited as
07~01~abc~data entry~Z3~data entry ASSISTANT~Z3~39
~01~~operator specialist~00~operator UNSPECIFIED~A0~00

can anybody help me on this in writing code for this


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: March 2, 2007 at 09:50:50 Pacific
Subject: how to get fixed width file in unix
Reply: (edit)

I'm interpreting that you want a carriage return at the first word that is all capital letters:

sed 's/ /~/g' d.file|
awk ' BEGIN { FS = "~"; OFS = "~" }
{
ff=0
for (i=1; i<NF; i++)
if($i ~ /^[A-Z]+$/ && ff==0)
{
$i="\n"$i
ff=1
}
printf("%s\n", $0)
} '


Report Offensive Follow Up For Removal

Response Number 2
Name: ghostdog
Date: March 3, 2007 at 21:35:56 Pacific
Subject: how to get fixed width file in unix
Reply: (edit)

take note that OP doesn't want all spaces converted to ~


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: how to get fixed width file in unix

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge