Off Topic - Unix Question [message #23757] |
Thu, 02 January 2003 17:45 |
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|_1|_2|_3|_4
020-238-001|_2|_3|_1|_4
238-273-287|_4|_1|_2|_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 |
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="|" } { print $1 "|" substr($2,length($2)-1,length($2)) "|" substr($3,length($3)-1,length($3)) "|" substr($4,length($4)-1,length($4)) "|" substr($5,length($5)-1,length($5)) "|" substr($6,length($6)-1,length($6)) "|" 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
|
|
|