Sponsored Content
Top Forums Shell Programming and Scripting [Solved] Extract information according to values ​​defined Post 302891475 by jiam912 on Thursday 6th of March 2014 04:17:08 AM
Old 03-06-2014
I'm sorry to take your time with my questions. Unfortunately I am not an expert with awk but I'm slowly learning.

I am very grateful for the help that you and others profecionales working in this forum.

I learned a lot with the answers that have done me to questions. I have problems to understand how works the arrays.

Here is the script that I'm doing. At the end of this scrip that you can find the operation to capture status with the lines 14 and 98 but not especificimente as requested previpusly.

thanks for your help
Code:
#!/bin/csh
#           C-shell script file.                                                


set filename = `echo $1` 

awk '{if(/^A/)print $0}' $1 | awk '{\
         line = substr($0,1,128);\
     ln =substr($2,1,5);\
     vp =substr($3,1,5);\
     ind =substr($3,8,1);\
         printf("%-128s %5d%5d%1d\n", line,ln,vp,ind)}' > eff

#------------------------------------------------------------------------------------------------
# Compute the swath number ----------------------------------------------------------------------
#------------------------------------------------------------------------------------------------
awk '{\
     line = substr($0,1,141);\
     sw = (int((substr($2,1,5)-'$CSWN')/12)) ;\
     printf ("%-142s %3d\n",line,sw)\
     }' eff > eff1

set first_sw = `awk '{sw = substr($0,144,4) ; printf("%4s\n", sw)}' eff1 | sort -nru | head -1`

# Replace second swath - low side - swath number for high side

awk '{\
     sw  = substr($0,144,4) ;\
     dif = '$first_sw' - sw;\
     if ( dif < 17) {\
        line = substr($0,1,140);\
        sw   = sw - 18 ;\
        printf ("%-142s %3d\n",line,sw)\
        } else {\
               print $0\
               }\
      }' eff1 > eff2


#------------------------------------------------------------------------------------------------
# sort vps by line and vp & index ---------------------------------------------------------------
#------------------------------------------------------------------------------------------------

cat eff2 | awk '{\
     lvp =substr($0,130,11);\
     ln =substr($2,1,7);\
     vp =substr($3,1,7);\
     ind =substr($3,8,1);\
     sw =substr($0,144,4);\
     x =substr($0,57,8);\
     y =substr($0,66,9);\
     tm =substr($0,119,8);\
     st =substr($0,91,2);\
         printf("%11d %5.1f %5.1f%1d %8.1f %9.1f %2d %8d %4d %5d%5d   \n", lvp,ln,vp,ind,x,y,st,tm,sw,ln,vp)}' | sort -nk1 > eff3

#------------------------------------------------------------------------------------------------
# To get XY average for vp   --------------------------------------------------------------------
#------------------------------------------------------------------------------------------------
#awk     '                       {A = substr ($0,119,8); B = substr ($0, 57, 8); C = substr ($0, 66, 9)}\
#         A != OA && NR > 1      {printf "%s%8.1f %9.1f%s\n", substr(D,1,56), SUM1/CNT, SUM2/CNT, substr(D,75); CNT=0; SUM1=SUM2=""}\
#         END                    {printf "%s%8.1f %9.1f%s\n", substr(D,1,56), SUM1/CNT, SUM2/CNT, substr(D,75); CNT=0; SUM1=SUM2=""}\
#                                {OA = A; D=$0; SUM1+=B; SUM2+=C; CNT++}\
#        ' eff 

awk     '                       {A = substr ($0,52,8); B = substr ($0, 30, 8); C = substr ($0, 39, 9)}\
         A != OA && NR > 1      {printf "%s%8.1f %9.1f%s\n", substr(D,1,29), SUM1/CNT, SUM2/CNT, substr(D,48); CNT=0; SUM1=SUM2=""}\
         END                    {printf "%s%8.1f %9.1f%s\n", substr(D,1,29), SUM1/CNT, SUM2/CNT, substr(D,48); CNT=0; SUM1=SUM2=""}\
                                {OA = A; D=$0; SUM1+=B; SUM2+=C; CNT++}\
        ' eff3 > eff4 


cat eff4 | sort -nk9 | awk '{if (x[$9]) {x_count[$9]++; print $0; if ( x_count[$9] == 1 ) {print x[$9]}} x[$9] =$0}' | sort -nk1 > eff5

cat eff5 | awk '{a = substr($0,13,16); print a}' > eff6

##o get all vps reshoted
grep -hFf eff6 eff2 | sort -k1.130,140bn > eff7

grep -vFf eff6 eff2 | sort -k1.130,140bn > eff8

#get bad VPS with wrong status not reshoted
cat eff8 | awk '{if(substr($0,91,2) == 14) print $0; else if(substr($0,91,2) == 98) print $0}'

#rm -f *tmp* *eff*

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk to extract lines with a defined number of characters

This is my problem, my file (file A) contains the following information: Now, I would like to create a file (file B) containing only the lines with 10 or more characters but less than 20 with their corresponding ID: Then, I need to compare the entries and determine their frequency. Thus, I... (7 Replies)
Discussion started by: Xterra
7 Replies

2. HP-UX

[Solved] processor type and bit information

Hi, I'm trying to download a compatible Oracle Client software for a HP-UX machine. I'd like to know if ... 1) HP-UX is 32 bit or 64 bit? 2) Processor type - Itanium or regular? when I execute uname -a I get HP-UX B.11.11 U 9000/800 728684161 unlimited-user license Based on the... (7 Replies)
Discussion started by: luft
7 Replies

3. Shell Programming and Scripting

[solved] awk: placement of user-defined functions

Hi folks, is there any recommendation, especially from a point of performance, about where to place a user-defined function in awk, like in BEGIN{} or if it is only need once at the end in END{}? Or doesn't it matter at all since, awk is so clever and only interprets it once, wherever it is... (3 Replies)
Discussion started by: zaxxon
3 Replies

4. Shell Programming and Scripting

[Solved] Editing the alphabet's based on position information

I do have a file of the following format file 1 >SAM ATGCTCCTTAGCTACGTAGCAAGTAGAAAAAA AGCGCGAGCATTGAAGCGGAGGAGAGGAGGA TGAGATGATGACCCAGTATAAAGAGTGATGAT like this above file. file 1 has 1000's of lines. I would like to edit this file1 using the information from file2 (see below), by... (16 Replies)
Discussion started by: Lucky Ali
16 Replies

5. UNIX for Advanced & Expert Users

[Solved] Unable to fetch the UNIX variable information

I am having a file called variable_info.ksh in that file I am having following global variable information like… EMAIL_PATH=/var/mail TMP_PATH=/home/tmp And we are having another temporary parameter file abcd.txt, in that file we are having the following information like… EMAIL|EMAI_PATH I... (4 Replies)
Discussion started by: mesahammad
4 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Variable defined in .bashrc not intializing in script

I have the variable defined in .bashrc BIN_DIR="/usr/local/dw" and in my shell script i am using below. #!/bin/bash echo "Bin Dir: ${BIN_DIR}" . "${BIN_DIR}"/dwh_Loadfuncs.sh Output: Bin Dir: /usr/local/dw/dwh_LoadXMLFileIntoStage.sh: line 7: /dwh_Loadfuncs.sh: No such file or... (3 Replies)
Discussion started by: Ariean
3 Replies

7. Shell Programming and Scripting

[Solved] How can I pull specific information from PS?

I need to grab information from the output of the ps command. For each line of ps output that contains _progres -b I need to get the word that follows -p. The "-p" can be anywhere after "_progres -b". Using grep to select the correct lines is no problem (e.g. ps -ef|grep "_progres \-b|grep -v... (3 Replies)
Discussion started by: Papa Lee
3 Replies

8. Shell Programming and Scripting

[Solved] Extracting information from DDL's

Dear Experts, I need your help here. I have lot of teradata DDL's as follows, i want to extract field names , field attributes and NOT NULL information from DDL.Could you please help here. Sample DDL: CREATE MULTISET TABLE APS_CALL_IN_PICKUP_CANCELED ,NO FALLBACK , NO BEFORE... (2 Replies)
Discussion started by: srikanth38
2 Replies

9. SCO

How to measure disk IO 5.0.7? (sar, return values ​​are not valid)

Hello I am analyzing disk performance OSR5.0.7 running inside VirtualBox. GUEST: osr5.0.7; 1GB ram; raw disk HOST: SLES11SP3, 4GB ram; 1 disc SATA2-7200rpm But I'm not sure how to do it right (the values ​​returned by sar not match the values ​​of the physical machine) The attributes... (0 Replies)
Discussion started by: flako
0 Replies

10. Shell Programming and Scripting

Sum values of specific column in multiple files, considering ranges defined in another file

I have a file (let say file B) like this: File B: A1 3 5 A1 7 9 A2 2 5 A3 1 3 The first column defines a filename and the other two define a range in that specific file. In the same directory, I have also three more files (File A1, A2 and A3). Here is 10 sample lines... (3 Replies)
Discussion started by: Bastami
3 Replies
All times are GMT -4. The time now is 07:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy