Home » Infrastructure » Unix » Off Topic - Unix Question
Off Topic - Unix Question [message #23757] Thu, 02 January 2003 17:45 Go to next message
Rizwan Qazi
Messages: 135
Registered: August 2002
Senior Member
Nobody answers questions on the Unix forum on this website so I am bringing the question here. Kind of urgent so I would appreciate it if someone can help

Suppose I have a | delimited file which looks like

011-272-000��_1��_2��_3��_4
020-238-001��_2��_3��_1��_4
238-273-287��_4��_1��_2��_3
....

How can I edit this file with a shell script or a
command so that the final file looks like

011-272-000&#124_1&#124_2&#124_3&#124_4
020-238-001&#124_2&#124_3&#124_1&#124_4
238-273-287&#124_4&#124_1&#124_2&#124_3
....

Please note that I want this script to be able do this
with any number of fields.

Rizwan
Re: Off Topic - Unix Question [message #23763 is a reply to message #23757] Fri, 03 January 2003 05:32 Go to previous message
Rizwan Qazi
Messages: 135
Registered: August 2002
Senior Member
Hi Everyone,

The OS install does not have PERL so I am compelled to use awk. I was able to create a shell

cat $1 | awk 'BEGIN { FS="&#124" } { print $1 "&#124" substr($2,length($2)-1,length($2)) "&#124" substr($3,length($3)-1,length($3)) "&#124" substr($4,length($4)-1,length($4)) "&#124" substr($5,length($5)-1,length($5)) "&#124" substr($6,length($6)-1,length($6)) "&#124" substr($7,length($7)-1,length($7))}'

which allowed me to do what I set out to do. However, if fields change then I will be forced to modify this script. Is there a way to accomplish this with a for or while loop within awk

Rizwan
Previous Topic: Re: problem : install Oracle 8.1.7 on Slackware 7.1
Next Topic: Re: how to run a stored proc from shell file?
Goto Forum:
  


Current Time: Tue Nov 26 05:57:39 CST 2024