I have a file something like this:
H|ACCT|XEC|1|TEMP|20130215035845 849002|48|1208004|100|||1 849007|28|1208004|100|||1 T|2|3
Note that there are extra empty lines at the end of the file.
I want to replace the value of column 5 with column 4's value in all the lines except first and last non-blank line.
I cannot rely on the number of fields as the last line may have as many fields as the other ones, nor on the lines to modify always starting with a number.
I tried the code below:
awk 'BEGIN{FS="|"; OFS="|"} {$5=$4; print}' in.txt
Output is:
H|ACCT|XEC|1|1|20130215035845
||||
849002|48|1208004|100|100||1
||||
849007|28|1208004|100|100||1
||||
T|2|3||
||||
||||
||||
Expected output:
H|ACCT|XEC|1|TEMP|20130215035845| 849002|48|1208004|100|100||1 849007|28|1208004|100|100||1 T|2|3
How can I skip the first and last non-blank lines from getting changed? I also want to skip blank lines.