Fix script to get missing information


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fix script to get missing information
# 1  
Old 11-30-2014
Fix script to get missing information

Gents,

Can you please help me to fix the following script in order to get complete data as desired. I am missing some data in output.

the complete input file is attached.

The script I am using is

Code:
awk '{\
       status=substr($0,91,2)\
       ind=substr($0,26,1);\
       split(substr($0, 11, 24-11), val,/\.0 /);\
       key[NR%2":"val[1]val[2]] = ind":"status\
     }\
     END{\
       for(i in key){\
         split(i, arr, /:/)\
         split(key[i], brr, /:/)\
         if(!(brr[2] == '$st1' || brr[2] == '$st2')){\
           delete key[i]\
           continue\
         }\
         cnt[arr[2]]++\
      }\
      for(i in key){\
        split(i, arr, /:/)\
        split(key[i], brr, /:/)\
        print arr[2]" index "brr[1]" has "cnt[arr[2]]" times status "brr[2]\
      }\
    }' input.txt | sort -k1,1n -u > output

Output I get

Code:
6936919969 index 2 has 2 times status 14
6937919401 index 3 has 2 times status 14
6938720105 index 2 has 2 times status 14
6957719489 index 4 has 2 times status 98
6957919489 index 2 has 2 times status 98
6958119529 index 2 has 2 times status 14
6958320209 index 2 has 2 times status 14
6958719737 index 2 has 2 times status 14
6958920185 index 2 has 2 times status 14
6959120009 index 1 has 1 times status 98
6959320089 index 1 has 1 times status 98

Output I will like to get

Code:
6936919969 index 2 has 2 times status 14
6937919401 index 2 has 2 times status 14
6937919401 index 3 has 2 times status 14
6938720105 index 2 has 2 times status 14
6957719489 index 1 has 2 times status 98
6957719489 index 2 has 2 times status 98
6957719489 index 3 has 2 times status 98
6957719489 index 4 has 2 times status 98
6957919489 index 1 has 2 times status 98
6957919489 index 2 has 2 times status 98
6958119529 index 2 has 2 times status 14
6958320209 index 2 has 2 times status 14
6958719737 index 2 has 2 times status 14
6958920185 index 2 has 2 times status 14
6959120009 index 1 has 1 times status 98
6959320089 index 1 has 1 times status 98

Thanks for your help
# 2  
Old 11-30-2014
What is or refers to '$st1' and '$st2'?
# 3  
Old 11-30-2014
Dear RudiC
Sorry they are variables

Code:
$st1=14
$st2=98

# 4  
Old 11-30-2014
Remove the option -u from sort
Code:
sort -k1,1n -u > output


Last edited by junior-helper; 11-30-2014 at 10:57 PM.. Reason: formatting ;)
# 5  
Old 12-01-2014
I've rarely seen a file and a logic as strange as this ones. In principle, you are overwriting the array elements as your index is not unique. You could try to make it unique, and then increment the array value each time you encounter the index.
This User Gave Thanks to RudiC For This Post:
# 6  
Old 12-01-2014
Dear RudiC,

Please can you help me to get the desired output. from the input file. I try to get it myself but I cant . Thanks for your help

---------- Post updated at 08:27 AM ---------- Previous update was at 08:26 AM ----------

Dear RudiC,

Please can you help me to get the desired output. from the input file. I try to get it myself but I cant . Thanks for your help

---------- Post updated at 09:32 AM ---------- Previous update was at 08:27 AM ----------

Quote:
Originally Posted by junior-helper
Remove the option -u from sort
Code:
sort -k1,1n -u > output

Hi Thanks it don't help
# 7  
Old 12-01-2014
I largely reduced the logics, maybe a bit too far, but it seems to do what you want and gets way more output lines than defined in the sample. Try
Code:
awk     '       {status=substr($0,91,2)
                 ind=substr($0,26,1)
                 split(substr($0, 11, 24-11), val,/\.0 /)
                 key[val[1]val[2]":"ind":"status]++
                 }
         END    {for(i in key)  {split(i, brr, /:/)
                                 if ((brr[3] == 14) || (brr[3] == 98))
                                        print brr[1]" index "brr[2]" has "key[i]" times status " brr[3]
                }
        ' /tmp/input.txt | sort -k1,1n
6936119601 index 1 has 2 times status 98
6936919969 index 2 has 2 times status 14
6937319385 index 1 has 2 times status 98
6937719401 index 1 has 2 times status 98
6937719401 index 2 has 2 times status 98
6937919401 index 2 has 2 times status 14
6937919401 index 3 has 2 times status 14
6938119313 index 1 has 2 times status 98
6938519977 index 1 has 1 times status 14
.
.
.
6960519681 index 1 has 2 times status 98
6960519681 index 2 has 2 times status 98
6960519681 index 3 has 2 times status 98

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Missing information in output file

Gents, Using the following code i am able to output the information i need, but some of the strings are not complete due to the separator : used.. Kindly can u help me to get all string after the first : Example in the output file column 16 i should get 17/11/25 03:43:51:732000 but i... (8 Replies)
Discussion started by: jiam912
8 Replies

2. Shell Programming and Scripting

My script failed and can't fix it ?

Hi , I'd like to give you a little bit idea about my script which is used to get any generated file from remote server using ftp session then organized those file into directories based on their date ( at the end I supposed to have 1 months directories 20130401 20130402 ....20130430 ,... (27 Replies)
Discussion started by: arm
27 Replies

3. Shell Programming and Scripting

How to fix my IMDB Script

Hello, I am using IMDB bot file for my movie site.. But I get this message like this---Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in... (2 Replies)
Discussion started by: lg2013
2 Replies

4. UNIX for Dummies Questions & Answers

Please help to fix awk script

Good morning, fellows. I would need to ask for your help in editing my awk script. Here is the original version: BEGIN { printf ("CRYST1 200.000 200.000 200.000 90.00 90.00 90.00 P 1 1\n") maxatoms=1000 natom=0 found_struct = 0 found_bond = 0 } { if( NF == 5 ) { foundff=0 natom++... (9 Replies)
Discussion started by: snysmumrik
9 Replies

5. Windows & DOS: Issues & Discussions

Fix script error (%%n)

Hi, I'm currently tinkering with a script that uses the for command to process all *.gif files in the current folder. I marked the spot where it exits out with an error by adding a "pause" The error message given is: convert.exe: unable to open image `%x': No such file or directory @... (2 Replies)
Discussion started by: pasc
2 Replies

6. Shell Programming and Scripting

Fix CSV file with column missing quotes

I have a CSV file that is missing quotes around a column that contains text with commas. Example: Column1, Column2, Column3, Column4, Column5, Column6 Data1, Data2, Data3, Data, 4, Data5, Data6 Data1, Data3, Data3, Data, text, 4, Data5, Data6 I think the easiest way for me to fix this is to... (2 Replies)
Discussion started by: EmptyH
2 Replies

7. Shell Programming and Scripting

how to fix this awk script?

i have a log file while looks like this ++ user_a blabla blabla nas_b blabla user_d this is a user_a junk line another junk line user_c nas_m blabla ++ basically most of the lines contain a "user" keywords, and the rest of the lines do not have "user" at all. So I have the... (17 Replies)
Discussion started by: fedora
17 Replies

8. Shell Programming and Scripting

fix a problem in this script

z=9 i=0 h=02 min=55 while do cat /home/barmecha/test | grep $h:$min >> /home/barmecha/file1 min=`expr $min + 1` if ; then h=`expr $h + 1` fi i=`expr $i + 1` done i have a log file with time wise log in it, this script help me to pull out logs of the give time interval...but the... (8 Replies)
Discussion started by: abhishek27
8 Replies

9. Linux

missing in script

Hi , I am trying to make this change work in my script but its not working.The idea is to grep for "CREATE VIEW" and then change view name from orig to VW_orig. but the problem comes when there is no schema prefix to the view name . the code I am using is #!/bin/ksh... (5 Replies)
Discussion started by: capri_drm
5 Replies
Login or Register to Ask a Question