Extra data in output file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extra data in output file
# 1  
Old 02-28-2015
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 Smilie
# 2  
Old 02-28-2015
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!
# 3  
Old 03-01-2015
Hi Don Cragun,

Sorry to upload all the file.

Here short explanation of the case.
Input file
Code:
--------------------------------------------------------------------------------------------------------------

		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,
Code:
 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.
Code:
 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

Code:
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
# 4  
Old 03-01-2015
How about
Code:
awk     '/Swath/        {split ($0, SWATH, " ")}
         /^-+$/ && P    {print; P=0}
         $2~/R|S/       {$1=$1; print $0, SWATH[2]; P=1}
        ' FS="|" file

This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-01-2015
Dear RudiC

You are great. Thanks for your help

It works perfect and quickly Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script when scheduled in Crontab gives extra records in output

Hi, We have created a script that's checks the latency of IIDR subscription by fetching details from a config file (that contains subscription details) and running the CHCCLP command. The out put is then concatenated in a csv file. Once all subscription details are saved the script send a mail... (7 Replies)
Discussion started by: ab095
7 Replies

2. Shell Programming and Scripting

awk to reformat output if input file is empty, but not if file has data in it

The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format: input chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18 chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Extra Space in output - remove

Hi All I am trying to perform the below operation -count=`cat abc.txt | wc -l` echo$count 5 Head=Start"$DATE"00000"$count"File echo $HEAD START15020300000 5File There is a space coming before 5 which is not needed . How to ignore that . (4 Replies)
Discussion started by: honey26
4 Replies

4. Shell Programming and Scripting

Help with add existing file name as new data column in new output file

Input File 1 cat S1.txt MI0043 2731 miR-1 Input File 2 cat S4.txt MI006 310 CiR-1 MI057 10 CiR-24 MI750 5 CiR-24 Desired Output File 1 cat S1.txt.out MI0043 2731 miR-1 S1.txt Desired Output File 2 cat S4.txt.out MI006 310 CiR-1 S4.txt (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. Shell Programming and Scripting

Output all data of files into one file

I have three files (can be more than 3): cat Katty => d4r4ff5rf5 123.44.32.4 =>cat Manu ffrs44frfrf 123.33.44.3 =>cat Chris derfe5rgrg 134.4.55.4 So basically, these files are in /Users/Unknown/files/*. Files can be... (11 Replies)
Discussion started by: Manu1234567
11 Replies

6. Shell Programming and Scripting

How to fill data from other file and get some output

Greetings, I have a hard time creating a large number of user profiles in a database. The data file looks like this : 01/01/80 Mitch Conley . . . . And I need to put the output into: Name: Mitch Surname: Conley Birthday: 01/01/80 Thanks in advance! (3 Replies)
Discussion started by: hemo21
3 Replies

7. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

8. Shell Programming and Scripting

Output from sql session having an extra whitespace

I am running a sql session within a shell script. Later I am performing some validations on the value coming from the sql session. The problem is that, the value I am getting from sql session have an extra white space at the begining(I am actually, assigning the outcome of the sql session to a... (5 Replies)
Discussion started by: mady135
5 Replies

9. Filesystems, Disks and Memory

vxdisk list output showing extra LUNs

hi fren i am facing this problem i have sun 6140 storage 30 volumes bt my vxdisk list output is showing 37 disk which shd nt b there has neone faced this proble earlier vxdiks list output is like this SUN6140-2_0 auto - - online c4t201700A0B84853C0d2s2 SUN6140-2_1 auto - - online... (13 Replies)
Discussion started by: bond_ankur
13 Replies

10. Shell Programming and Scripting

Extra output in the script

Hi , I am trying to execute the following script. #!/bin/sh find . -name "common.log.diff" if ; then cp common.log common.log.diff diff common.log common.log.diff > DIFFERENCE.log cp common.log common.log.diff grep "ERROR" DIFFERENCE.log if ; then echo "1" else echo "0" fi... (5 Replies)
Discussion started by: himvat
5 Replies
Login or Register to Ask a Question