0

I have a | delimited file with 132 fields in every record, what I need to do is append the last 2 bytes in field 3 to field 1 than print the entire record:

example of the input record

field1  field2  field3   field4 field5 .... field 132
123456  xyz     01/28/99 xyz123 xyz145 .... xyz567  

the output should be:

field1   field2  field3   field4 field5 .... field 132
12345699 xyz     01/28/99 xya123 xyz145 .... xyz567

Here's the script that I have:

#!/bin/ksh
IFS="|"
while read a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11; do
    yy=`expr substr "$a3" 7 2`
    acyy=$a1$yy
    print $acyy $a2 $a3 $a4 $a5 $a6 $a7 $a8 $a9 $a10 $a11
done < infile.txt  > outfile.txt

is there a way to read and print all remaining fileds?

Please help and thank you

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
  • What's wrong with what you have? (It looks right to me). Show us some sample output that illustrates the problem. – shellter Mar 29 '11 at 16:50

1 Answers1

2

aren't 'leftover' words all assigned to the last parameter to read? (including separator, |) if you don't want the separators just 'sed' the last param - e.g., $(echo "$a11" | sed 's/|/ /')

Jay
  • 435
  • 3
  • 5