Extra data in output file

Gents,

I did a small scritp called make_file

It read file1.txt file and generate an output as attached.. But the script is showing more extra information not needed.

I have attached the output file as desired.

Could you please help to fix this scrip to get the correct output

Thanks :b:

So, you give us uncommented code that does the wrong thing.
You show us an output file that contains 1Mb more than you want and an output file that contains what you want.
And, you want us to guess at what output you are trying to produce and guess at what the extra 1Mb is.

How about adding some comments to your code saying what each step is supposed to do?
How about describing what |S| and |R| records are?
How about describing in English what the output is supposed to be and how the input is supposed to be transformed into the output?

Can't you give us a representative input file of a few thousand bytes and the corresponding output that should be produced from that sample input. And, can't you post them in the thread instead of expecting volunteers to download 6.6Mb and guess at what you are trying to do?

Please help us help you. Describe what you are trying to do!

Hi Don Cragun,

Sorry to upload all the file.

Here short explanation of the case.
Input file

--------------------------------------------------------------------------------------------------------------

		Swath  1103
--------------------------------------------------------------------------------------------------------------
| |   Line Name     ||                 First Point              ||                  Last Point              ||
| |                 ||Point Num|  I  |  J  |    X    |     Y    ||Point Num|  I  |  J  |    X    |     Y    ||
--------------------------------------------------------------------------------------------------------------
|R| 64448           ||  19110.0|19110|64448| 325130.9| 2751202.4||  19648.0|19648|64448| 336779.0| 2757927.4||
|R| 64460           ||  19110.0|19110|64460| 324980.9| 2751462.2||  19664.0|19664|64460| 336975.4| 2758387.2||
|R| 64472           ||  19110.0|19110|64472| 324830.9| 2751722.0||  19664.0|19664|64472| 336825.4| 2758647.0||
|R| 64484           ||  19118.0|19118|64484| 324854.1| 2752081.8||  19680.0|19680|64484| 337021.8| 2759106.8||
|R| 64496           ||  19114.0|19114|64496| 324617.5| 2752291.7||  19680.0|19680|64496| 336871.8| 2759366.7||
|R| 64508           ||  19110.0|19110|64508| 324380.9| 2752501.5||  19704.0|19704|64508| 337241.4| 2759926.5||
|R| 64520           ||  19112.0|19112|64520| 324274.2| 2752786.3||  19704.0|19704|64520| 337091.4| 2760186.3||
|R| 64532           ||  19114.0|19114|64532| 324167.5| 2753071.1||  19720.0|19720|64532| 337287.8| 2760646.1||
|R| 64544           ||  19112.0|19112|64544| 323974.2| 2753305.9||  20032.0|20032|64544| 343892.8| 2764805.9||
--------------------------------------------------------------------------------------------------------------

		Swath  1103
--------------------------------------------------------------------------------------------------------------
| |   Line Name     ||                 First Point              ||                  Last Point              ||
| |                 ||Point Num|  I  |  J  |    X    |     Y    ||Point Num|  I  |  J  |    X    |     Y    ||
--------------------------------------------------------------------------------------------------------------
|S| 64545           ||  19113.0|19113|64545| 323983.4| 2753340.0||  20033.0|20033|64545| 343902.0| 2764840.0||
|S| 64547           ||  19113.0|19113|64547| 323958.4| 2753383.3||  20033.0|20033|64547| 343877.0| 2764883.3||
|S| 64549           ||  19113.0|19113|64549| 323933.4| 2753426.6||  20033.0|20033|64549| 343852.0| 2764926.6||
|S| 64551           ||  19113.0|19113|64551| 323908.4| 2753469.9||  20033.0|20033|64551| 343827.0| 2764969.9||
|S| 64553           ||  19113.0|19113|64553| 323883.4| 2753513.2||  20033.0|20033|64553| 343802.0| 2765013.2||
|S| 64555           ||  19113.0|19113|64555| 323858.4| 2753556.5||  20033.0|20033|64555| 343777.0| 2765056.5||
--------------------------------------------------------------------------------------------------------------

		Swath  1104
--------------------------------------------------------------------------------------------------------------
| |   Line Name     ||                 First Point              ||                  Last Point              ||
| |                 ||Point Num|  I  |  J  |    X    |     Y    ||Point Num|  I  |  J  |    X    |     Y    ||
--------------------------------------------------------------------------------------------------------------
|R| 64472           ||  19110.0|19110|64472| 324830.9| 2751722.0||  19664.0|19664|64472| 336825.4| 2758647.0||
|R| 64484           ||  19118.0|19118|64484| 324854.1| 2752081.8||  19680.0|19680|64484| 337021.8| 2759106.8||
|R| 64496           ||  19114.0|19114|64496| 324617.5| 2752291.7||  19680.0|19680|64496| 336871.8| 2759366.7||
|R| 64508           ||  19110.0|19110|64508| 324380.9| 2752501.5||  19704.0|19704|64508| 337241.4| 2759926.5||
|R| 64520           ||  19112.0|19112|64520| 324274.2| 2752786.3||  19704.0|19704|64520| 337091.4| 2760186.3||
|R| 64532           ||  19114.0|19114|64532| 324167.5| 2753071.1||  19720.0|19720|64532| 337287.8| 2760646.1||
|R| 64544           ||  19112.0|19112|64544| 323974.2| 2753305.9||  20032.0|20032|64544| 343892.8| 2764805.9||
|R| 64556           ||  19114.0|19114|64556| 323867.5| 2753590.7||  20064.0|20064|64556| 344435.6| 2765465.7||
|R| 64448           ||  19110.0|19110|64448| 325130.9| 2751202.4||  19648.0|19648|64448| 336779.0| 2757927.4||
|R| 64460           ||  19110.0|19110|64460| 324980.9| 2751462.2||  19664.0|19664|64460| 336975.4| 2758387.2||
--------------------------------------------------------------------------------------------------------------

		Swath  1104
--------------------------------------------------------------------------------------------------------------
| |   Line Name     ||                 First Point              ||                  Last Point              ||
| |                 ||Point Num|  I  |  J  |    X    |     Y    ||Point Num|  I  |  J  |    X    |     Y    ||
--------------------------------------------------------------------------------------------------------------
|S| 64557           ||  19113.0|19113|64557| 323833.4| 2753599.8||  20065.0|20065|64557| 344444.8| 2765499.8||
|S| 64559           ||  19113.0|19113|64559| 323808.4| 2753643.1||  20065.0|20065|64559| 344419.8| 2765543.1||
|S| 64561           ||  19113.0|19113|64561| 323783.4| 2753686.4||  20065.0|20065|64561| 344394.8| 2765586.4||
|S| 64563           ||  19113.0|19113|64563| 323758.4| 2753729.7||  20065.0|20065|64563| 344369.8| 2765629.7||
|S| 64565           ||  19113.0|19113|64565| 323733.4| 2753773.0||  20065.0|20065|64565| 344344.8| 2765673.0||
|S| 64567           ||  19113.0|19113|64567| 323708.4| 2753816.3||  20065.0|20065|64567| 344319.8| 2765716.3||

output using the script I did,

 R  64448               19110.0 19110 64448  325130.9  2751202.4    19648.0 19648 64448  336779.0  2757927.4   1103 
 R  64460               19110.0 19110 64460  324980.9  2751462.2    19664.0 19664 64460  336975.4  2758387.2   1103 
 R  64472               19110.0 19110 64472  324830.9  2751722.0    19664.0 19664 64472  336825.4  2758647.0   1103 
 R  64484               19118.0 19118 64484  324854.1  2752081.8    19680.0 19680 64484  337021.8  2759106.8   1103 
 R  64496               19114.0 19114 64496  324617.5  2752291.7    19680.0 19680 64496  336871.8  2759366.7   1103 
 R  64508               19110.0 19110 64508  324380.9  2752501.5    19704.0 19704 64508  337241.4  2759926.5   1103 
 R  64520               19112.0 19112 64520  324274.2  2752786.3    19704.0 19704 64520  337091.4  2760186.3   1103 
 R  64532               19114.0 19114 64532  324167.5  2753071.1    19720.0 19720 64532  337287.8  2760646.1   1103 
 R  64544               19112.0 19112 64544  323974.2  2753305.9    20032.0 20032 64544  343892.8  2764805.9   1103 
 -----------------------------------------------------------------------------------------------------------------
 S  64545               19113.0 19113 64545  323983.4  2753340.0    20033.0 20033 64545  343902.0  2764840.0   1103 
 S  64547               19113.0 19113 64547  323958.4  2753383.3    20033.0 20033 64547  343877.0  2764883.3   1103 
 S  64549               19113.0 19113 64549  323933.4  2753426.6    20033.0 20033 64549  343852.0  2764926.6   1103 
 S  64551               19113.0 19113 64551  323908.4  2753469.9    20033.0 20033 64551  343827.0  2764969.9   1103 
 S  64553               19113.0 19113 64553  323883.4  2753513.2    20033.0 20033 64553  343802.0  2765013.2   1103 
 S  64555               19113.0 19113 64555  323858.4  2753556.5    20033.0 20033 64555  343777.0  2765056.5   1103 
 -----------------------------------------------------------------------------------------------------------------
 R  64448               19110.0 19110 64448  325130.9  2751202.4    19648.0 19648 64448  336779.0  2757927.4   1104 
 R  64460               19110.0 19110 64460  324980.9  2751462.2    19664.0 19664 64460  336975.4  2758387.2   1104 
 R  64472               19110.0 19110 64472  324830.9  2751722.0    19664.0 19664 64472  336825.4  2758647.0   1104 
 R  64484               19118.0 19118 64484  324854.1  2752081.8    19680.0 19680 64484  337021.8  2759106.8   1104 
 R  64496               19114.0 19114 64496  324617.5  2752291.7    19680.0 19680 64496  336871.8  2759366.7   1104 
 R  64508               19110.0 19110 64508  324380.9  2752501.5    19704.0 19704 64508  337241.4  2759926.5   1104 
 R  64520               19112.0 19112 64520  324274.2  2752786.3    19704.0 19704 64520  337091.4  2760186.3   1104 
 R  64532               19114.0 19114 64532  324167.5  2753071.1    19720.0 19720 64532  337287.8  2760646.1   1104 
 R  64544               19112.0 19112 64544  323974.2  2753305.9    20032.0 20032 64544  343892.8  2764805.9   1104 
 R  64472               19110.0 19110 64472  324830.9  2751722.0    19664.0 19664 64472  336825.4  2758647.0   1104 
 R  64484               19118.0 19118 64484  324854.1  2752081.8    19680.0 19680 64484  337021.8  2759106.8   1104 
 R  64496               19114.0 19114 64496  324617.5  2752291.7    19680.0 19680 64496  336871.8  2759366.7   1104 
 R  64508               19110.0 19110 64508  324380.9  2752501.5    19704.0 19704 64508  337241.4  2759926.5   1104 
 R  64520               19112.0 19112 64520  324274.2  2752786.3    19704.0 19704 64520  337091.4  2760186.3   1104 
 R  64532               19114.0 19114 64532  324167.5  2753071.1    19720.0 19720 64532  337287.8  2760646.1   1104 
 R  64544               19112.0 19112 64544  323974.2  2753305.9    20032.0 20032 64544  343892.8  2764805.9   1104 
 R  64556               19114.0 19114 64556  323867.5  2753590.7    20064.0 20064 64556  344435.6  2765465.7   1104 
 R  64448               19110.0 19110 64448  325130.9  2751202.4    19648.0 19648 64448  336779.0  2757927.4   1104 
 R  64460               19110.0 19110 64460  324980.9  2751462.2    19664.0 19664 64460  336975.4  2758387.2   1104 
 -----------------------------------------------------------------------------------------------------------------
 S  64557               19113.0 19113 64557  323833.4  2753599.8    20065.0 20065 64557  344444.8  2765499.8   1104 
 S  64559               19113.0 19113 64559  323808.4  2753643.1    20065.0 20065 64559  344419.8  2765543.1   1104 
 S  64561               19113.0 19113 64561  323783.4  2753686.4    20065.0 20065 64561  344394.8  2765586.4   1104 
 S  64563               19113.0 19113 64563  323758.4  2753729.7    20065.0 20065 64563  344369.8  2765629.7   1104 
 S  64565               19113.0 19113 64565  323733.4  2753773.0    20065.0 20065 64565  344344.8  2765673.0   1104 
 S  64567               19113.0 19113 64567  323708.4  2753816.3    20065.0 20065 64567  344319.8  2765716.3   1104 
 -----------------------------------------------------------------------------------------------------------------

OUTPUT desired.

 R  64448               19110.0 19110 64448  325130.9  2751202.4    19648.0 19648 64448  336779.0  2757927.4   1103 
 R  64460               19110.0 19110 64460  324980.9  2751462.2    19664.0 19664 64460  336975.4  2758387.2   1103 
 R  64472               19110.0 19110 64472  324830.9  2751722.0    19664.0 19664 64472  336825.4  2758647.0   1103 
 R  64484               19118.0 19118 64484  324854.1  2752081.8    19680.0 19680 64484  337021.8  2759106.8   1103 
 R  64496               19114.0 19114 64496  324617.5  2752291.7    19680.0 19680 64496  336871.8  2759366.7   1103 
 R  64508               19110.0 19110 64508  324380.9  2752501.5    19704.0 19704 64508  337241.4  2759926.5   1103 
 R  64520               19112.0 19112 64520  324274.2  2752786.3    19704.0 19704 64520  337091.4  2760186.3   1103 
 R  64532               19114.0 19114 64532  324167.5  2753071.1    19720.0 19720 64532  337287.8  2760646.1   1103 
 R  64544               19112.0 19112 64544  323974.2  2753305.9    20032.0 20032 64544  343892.8  2764805.9   1103 
 -----------------------------------------------------------------------------------------------------------------
 S  64545               19113.0 19113 64545  323983.4  2753340.0    20033.0 20033 64545  343902.0  2764840.0   1103 
 S  64547               19113.0 19113 64547  323958.4  2753383.3    20033.0 20033 64547  343877.0  2764883.3   1103 
 S  64549               19113.0 19113 64549  323933.4  2753426.6    20033.0 20033 64549  343852.0  2764926.6   1103 
 S  64551               19113.0 19113 64551  323908.4  2753469.9    20033.0 20033 64551  343827.0  2764969.9   1103 
 S  64553               19113.0 19113 64553  323883.4  2753513.2    20033.0 20033 64553  343802.0  2765013.2   1103 
 S  64555               19113.0 19113 64555  323858.4  2753556.5    20033.0 20033 64555  343777.0  2765056.5   1103 
 -----------------------------------------------------------------------------------------------------------------
 R  64472               19110.0 19110 64472  324830.9  2751722.0    19664.0 19664 64472  336825.4  2758647.0   1104 
 R  64484               19118.0 19118 64484  324854.1  2752081.8    19680.0 19680 64484  337021.8  2759106.8   1104 
 R  64496               19114.0 19114 64496  324617.5  2752291.7    19680.0 19680 64496  336871.8  2759366.7   1104 
 R  64508               19110.0 19110 64508  324380.9  2752501.5    19704.0 19704 64508  337241.4  2759926.5   1104 
 R  64520               19112.0 19112 64520  324274.2  2752786.3    19704.0 19704 64520  337091.4  2760186.3   1104 
 R  64532               19114.0 19114 64532  324167.5  2753071.1    19720.0 19720 64532  337287.8  2760646.1   1104 
 R  64544               19112.0 19112 64544  323974.2  2753305.9    20032.0 20032 64544  343892.8  2764805.9   1104 
 R  64556               19114.0 19114 64556  323867.5  2753590.7    20064.0 20064 64556  344435.6  2765465.7   1104 
 R  64448               19110.0 19110 64448  325130.9  2751202.4    19648.0 19648 64448  336779.0  2757927.4   1104 
 R  64460               19110.0 19110 64460  324980.9  2751462.2    19664.0 19664 64460  336975.4  2758387.2   1104 
 -----------------------------------------------------------------------------------------------------------------
 S  64557               19113.0 19113 64557  323833.4  2753599.8    20065.0 20065 64557  344444.8  2765499.8   1104 
 S  64559               19113.0 19113 64559  323808.4  2753643.1    20065.0 20065 64559  344419.8  2765543.1   1104 
 S  64561               19113.0 19113 64561  323783.4  2753686.4    20065.0 20065 64561  344394.8  2765586.4   1104 
 S  64563               19113.0 19113 64563  323758.4  2753729.7    20065.0 20065 64563  344369.8  2765629.7   1104 
 S  64565               19113.0 19113 64565  323733.4  2753773.0    20065.0 20065 64565  344344.8  2765673.0   1104 
 S  64567               19113.0 19113 64567  323708.4  2753816.3    20065.0 20065 64567  344319.8  2765716.3   1104 
 -----------------------------------------------------------------------------------------------------------------

my script

file=file1.txt
fsw=`awk '/Swath/ {print $2}' file1.txt | uniq | sort -n | head -1`
lsw=`awk '/Swath/ {print $2}' file1.txt | uniq | sort -n | tail -1`

   sed -e 's/|/ /g'\
       -e 's/-/    /g' $file | grep -E "S|Swath" > tmpS
 
   sed -e 's/|/ /g'\
       -e 's/-/    /g' $file | grep -E "R|Swath" | sed '$d' > tmpR

cat tmpS tmpR > eff
 
if [ $fsw -gt 0 ]; then
       for sw in $(seq $fsw $lsw)
do
next_sw=$(($sw + 1))
          awk '/Swath  '"$sw"'/,/Swath  '"$next_sw"'/ { printf ("%-108s %3s \n", $0, '$sw') }' eff | grep "R " >> "output
          printf " -----------------------------------------------------------------------------------------------------------------\n" >> "output
          awk '/Swath  '"$sw"'/,/Swath  '"$next_sw"'/ { printf ("%-108s %3s \n", $0, '$sw') }' eff | grep "S " >> "output
          printf " -----------------------------------------------------------------------------------------------------------------\n" >> "output
done
fi

I have grep S and R to have a complete database from input file.
but the script prints always at the last occurrence all Lines where he find R, So I don't understand why he print all R again. This is only my problem otherwise the code works fine.

Thanks for your help

How about

awk     '/Swath/        {split ($0, SWATH, " ")}
         /^-+$/ && P    {print; P=0}
         $2~/R|S/       {$1=$1; print $0, SWATH[2]; P=1}
        ' FS="|" file
1 Like

Dear RudiC

You are great. Thanks for your help

It works perfect and quickly :slight_smile: