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

1
  • What's wrong with what you have? (It looks right to me). Show us some sample output that illustrates the problem. Commented Mar 29, 2011 at 16:50

1 Answer 1

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/|/ /')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.