AWK Looping. How can I get expected result?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Looping. How can I get expected result?
# 15  
Old 02-12-2013
Code:
diff  <(cut -f2- < file2) <(cut -f1- < file1)

this is printing something....how can I assign FS here.. file 1 is tab separated file 2 is space separated
# 16  
Old 02-12-2013
man cut?
Seems you are looking for matching fields instead of matching entire records (= rows, lines). cut -f2- will render field 2 up to end of line, -f1- the entire line. Drop the -- sign if you go for single fields only. And, use -d" "for the space delimiter.
# 17  
Old 02-12-2013
Code:
diff file1 file2

I tried above one after sorting of file
# 18  
Old 02-12-2013
there is something displaced

just re-typed the code with appropraite braces

Code:
~# awk 'FNR==1{i++}
{ for(k=1; k<=NF; k++){ A[i,FNR,k]=$k } }
END { for (i=1;i<=217;i++) { x=0;y=0; for(j=1; j<=2440;j++) { if(A[1,j,2]>=A[2,i,2]-0.1 && A[1,j,2]<=A[2,i,2]+0.1) { if(A[1,j,1]>=A[2,i,1])x=x+1;  if(A[1,j,1]<=A[2,i,1])y=y+1; }  }
if(x>=1 && y>=1) { print i,j,A[2,i,1],A[2,i,2]} } }' OFS="\t"  file1.pl file2.pl
awk 'FNR==1{i++}
{ for(k=1; k<=NF; k++){ A[i,FNR,k]=$k } }
END { for (i=1;i<=217;i++) { x=0;y=0; for(j=1; j<=2440;j++) { if(A[1,j,2]>=A[2,i,2]-0.1 && A[1,j,2]<=A[2,i,2]+0.1) { if(A[1,j,1]>=A[2,i,1])x=x+1;  if(A[1,j,1]<=A[2,i,1])y=y+1; }  }
if(x>=1 && y>=1) { print i,j,A[2,i,1],A[2,i,2]} } }' OFS="\t"  file1.pl file2.pl
1       2441    75.5    10.05
2       2441    75.02   10.15
3       2441    74.52   10.23
4       2441    74.02   10.33
5       2441    73.45   10.43
6       2441    73.15   10.48
8       2441    73.52   10.23
9       2441    73.98   10.13
10      2441    74.5    10.08
11      2441    74.98   10.05
12      2441    75.5    10
13      2441    75.5    10.05
14      2441    75      10.15
15      2441    74.5    10.23
16      2441    74      10.32
17      2441    73.5    10.42
18      2441    73      10.5
19      2441    75.5    10.07
20      2441    75      10.15
21      2441    74.5    10.23
22      2441    74      10.33
23      2441    73.5    10.42
24      2441    73      10.52
25      2441    72.7    10.57
26      2441    75.5    10.07
27      2441    75      10.15
28      2441    74.5    10.23
29      2441    74.02   10.32
30      2441    73.53   10.43
31      2441    73.02   10.5
32      2441    72.75   10.55
33      2441    75.83   9.98
34      2441    75.5    10.05
35      2441    75      10.15
36      2441    74.5    10.23
37      2441    74      10.32
38      2441    73.5    10.42
39      2441    73      10.52
40      2441    72.73   10.57
41      2441    75.83   9.97
42      2441    75.5    10.05
43      2441    75      10.15
44      2441    74.5    10.22
45      2441    74      10.32
46      2441    73.5    10.42
47      2441    73      10.5
48      2441    72.67   10.57
49      2441    72.75   10.55
50      2441    73.08   10.5
51      2441    73.5    10.4
52      2441    74      10.33
53      2441    74.5    10.23
54      2441    75.42   10.07
55      2441    75.83   9.97
56      2441    75.5    10
57      2441    74.92   10
58      2441    74.42   10.05
59      2441    74      10.05
60      2441    73.5    10.23
61      2441    73      10.42
62      2441    72.77   10.53
63      2441    75.83   9.8
64      2441    72.77   10.52
65      2441    73      10.42
66      2441    73.5    10.23
67      2441    74      10.05
68      2441    74.5    10.03
69      2441    75.25   10
70      2441    75.5    9.97
71      2441    76      9.95
72      2441    72.73   10.53
73      2441    73      10.48
74      2441    73.5    10.4
75      2441    74      10.32
76      2441    74.5    10.22
77      2441    75      10.12
78      2441    75.5    10.05
79      2441    75.67   10.02
80      2441    75.83   9.98
81      2441    75.83   10
82      2441    75.5    10.07
83      2441    75      10.17
84      2441    74.47   10.23
85      2441    74      10.33
86      2441    73.5    10.42
87      2441    72.97   10.5
88      2441    72.67   10.57
89      2441    75.83   10
90      2441    75.4    10.13
91      2441    74.98   10.33
92      2441    74.47   10.53
93      2441    73.98   10.72
94      2441    73.47   10.12
95      2441    73      10.37
96      2441    72.72   10.52
97      2441    75.83   9.98
98      2441    75.5    10.05
99      2441    75      10.13
100     2441    74.5    10.23
101     2441    74      10.32
102     2441    73.5    10.42
103     2441    73      10.5
104     2441    72.75   10.55
111     2441    89.53   19
112     2441    88.83   20
113     2441    88.47   20.5
114     2441    88.6    20.5
122     2441    89.6    19
123     2441    88.82   20
124     2441    88.47   20.5
132     2441    89.53   19
133     2441    88.8    20
134     2441    88.82   20
142     2441    89.78   19
143     2441    88.82   20
151     2441    89.5    19
152     2441    88.75   20
160     2441    89.53   19
161     2441    88.83   20
168     2441    89.6    19
169     2441    88.88   20
170     2441    75.83   9.98
171     2441    75.5    10.05
172     2441    75      10.13
173     2441    74.5    10.23
174     2441    74      10.32
175     2441    73.5    10.42
176     2441    73      10.48
177     2441    72.75   10.55
185     2441    89.17   19
186     2441    88.82   20
187     2441    75.82   9.92
188     2441    75.48   9.93
189     2441    75.02   9.97
190     2441    74.45   10
191     2441    74.02   10.03
192     2441    73.62   9.93
193     2441    72.7    10.57
194     2441    73      10.5
195     2441    73.5    10.42
196     2441    74      10.32
197     2441    74.5    10.23
198     2441    75      10.15
199     2441    75.5    10.05
200     2441    75.83   9.98
201     2441    72.67   10.57
202     2441    73.5    10.5
203     2441    73.5    10.42
204     2441    74      10.33
205     2441    74.5    10.23
206     2441    75      10.13
207     2441    75.5    10.05
208     2441    75.83   9.98
209     2441    75.83   9.98
210     2441    75.5    10.05
211     2441    75      10.13
212     2441    74.5    10.23
213     2441    74      10.33
214     2441    73.5    10.42
215     2441    73      10.52
216     2441    72.67   10.55
217     2441    75.83   10

---------- Post updated at 06:32 PM ---------- Previous update was at 06:31 PM ----------

sorry gues, wrong window selected...my apologies..

---------- Post updated at 06:33 PM ---------- Previous update was at 06:32 PM ----------

Just replaced and re-typed to appropriate places for the braces...


Code:
~# awk 'FNR==1{i++}
{ for(k=1; k<=NF; k++){ A[i,FNR,k]=$k } }
END { for (i=1;i<=217;i++) { x=0;y=0; for(j=1; j<=2440;j++) { if(A[1,j,2]>=A[2,i,2]-0.1 && A[1,j,2]<=A[2,i,2]+0.1) { if(A[1,j,1]>=A[2,i,1])x=x+1;  if(A[1,j,1]<=A[2,i,1])y=y+1; }  }
if(x>=1 && y>=1) { print i,j,A[2,i,1],A[2,i,2]} } }' OFS="\t"  file1.pl file2.pl
awk 'FNR==1{i++}
{ for(k=1; k<=NF; k++){ A[i,FNR,k]=$k } }
END { for (i=1;i<=217;i++) { x=0;y=0; for(j=1; j<=2440;j++) { if(A[1,j,2]>=A[2,i,2]-0.1 && A[1,j,2]<=A[2,i,2]+0.1) { if(A[1,j,1]>=A[2,i,1])x=x+1;  if(A[1,j,1]<=A[2,i,1])y=y+1; }  }
if(x>=1 && y>=1) { print i,j,A[2,i,1],A[2,i,2]} } }' OFS="\t"  file1.pl file2.pl
1       2441    75.5    10.05
2       2441    75.02   10.15
3       2441    74.52   10.23
4       2441    74.02   10.33
5       2441    73.45   10.43
6       2441    73.15   10.48
8       2441    73.52   10.23
9       2441    73.98   10.13
10      2441    74.5    10.08
11      2441    74.98   10.05
12      2441    75.5    10
13      2441    75.5    10.05
14      2441    75      10.15
15      2441    74.5    10.23
16      2441    74      10.32
17      2441    73.5    10.42
18      2441    73      10.5
19      2441    75.5    10.07
20      2441    75      10.15
21      2441    74.5    10.23
22      2441    74      10.33
23      2441    73.5    10.42
24      2441    73      10.52
25      2441    72.7    10.57
26      2441    75.5    10.07
27      2441    75      10.15
28      2441    74.5    10.23
29      2441    74.02   10.32
30      2441    73.53   10.43
31      2441    73.02   10.5
32      2441    72.75   10.55
33      2441    75.83   9.98
34      2441    75.5    10.05
35      2441    75      10.15
36      2441    74.5    10.23
37      2441    74      10.32
38      2441    73.5    10.42
39      2441    73      10.52
40      2441    72.73   10.57
41      2441    75.83   9.97
42      2441    75.5    10.05
43      2441    75      10.15
44      2441    74.5    10.22
45      2441    74      10.32
46      2441    73.5    10.42
47      2441    73      10.5
48      2441    72.67   10.57
49      2441    72.75   10.55
50      2441    73.08   10.5
51      2441    73.5    10.4
52      2441    74      10.33
53      2441    74.5    10.23
54      2441    75.42   10.07
55      2441    75.83   9.97
56      2441    75.5    10
57      2441    74.92   10
58      2441    74.42   10.05
59      2441    74      10.05
60      2441    73.5    10.23
61      2441    73      10.42
62      2441    72.77   10.53
63      2441    75.83   9.8
64      2441    72.77   10.52
65      2441    73      10.42
66      2441    73.5    10.23
67      2441    74      10.05
68      2441    74.5    10.03
69      2441    75.25   10
70      2441    75.5    9.97
71      2441    76      9.95
72      2441    72.73   10.53
73      2441    73      10.48
74      2441    73.5    10.4
75      2441    74      10.32
76      2441    74.5    10.22
77      2441    75      10.12
78      2441    75.5    10.05
79      2441    75.67   10.02
80      2441    75.83   9.98
81      2441    75.83   10
82      2441    75.5    10.07
83      2441    75      10.17
84      2441    74.47   10.23
85      2441    74      10.33
86      2441    73.5    10.42
87      2441    72.97   10.5
88      2441    72.67   10.57
89      2441    75.83   10
90      2441    75.4    10.13
91      2441    74.98   10.33
92      2441    74.47   10.53
93      2441    73.98   10.72
94      2441    73.47   10.12
95      2441    73      10.37
96      2441    72.72   10.52
97      2441    75.83   9.98
98      2441    75.5    10.05
99      2441    75      10.13
100     2441    74.5    10.23
101     2441    74      10.32
102     2441    73.5    10.42
103     2441    73      10.5
104     2441    72.75   10.55
111     2441    89.53   19
112     2441    88.83   20
113     2441    88.47   20.5
114     2441    88.6    20.5
122     2441    89.6    19
123     2441    88.82   20
124     2441    88.47   20.5
132     2441    89.53   19
133     2441    88.8    20
134     2441    88.82   20
142     2441    89.78   19
143     2441    88.82   20
151     2441    89.5    19
152     2441    88.75   20
160     2441    89.53   19
161     2441    88.83   20
168     2441    89.6    19
169     2441    88.88   20
170     2441    75.83   9.98
171     2441    75.5    10.05
172     2441    75      10.13
173     2441    74.5    10.23
174     2441    74      10.32
175     2441    73.5    10.42
176     2441    73      10.48
177     2441    72.75   10.55
185     2441    89.17   19
186     2441    88.82   20
187     2441    75.82   9.92
188     2441    75.48   9.93
189     2441    75.02   9.97
190     2441    74.45   10
191     2441    74.02   10.03
192     2441    73.62   9.93
193     2441    72.7    10.57
194     2441    73      10.5
195     2441    73.5    10.42
196     2441    74      10.32
197     2441    74.5    10.23
198     2441    75      10.15
199     2441    75.5    10.05
200     2441    75.83   9.98
201     2441    72.67   10.57
202     2441    73.5    10.5
203     2441    73.5    10.42
204     2441    74      10.33
205     2441    74.5    10.23
206     2441    75      10.13
207     2441    75.5    10.05
208     2441    75.83   9.98
209     2441    75.83   9.98
210     2441    75.5    10.05
211     2441    75      10.13
212     2441    74.5    10.23
213     2441    74      10.33
214     2441    73.5    10.42
215     2441    73      10.52
216     2441    72.67   10.55
217     2441    75.83   10

# 19  
Old 02-12-2013
Anyways thank you....RudyC has given me solution for this problem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep output to file result not as expected

Hi Gurus, I run command grep ABC file1 > file2 against below file. I got all ABC_xxx in one line in file2. I expect to get multiple lines in file2. If I print result in screen, the result is expected. thanks in advance My os is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ABC_123 XXXXX... (2 Replies)
Discussion started by: green_k
2 Replies

2. Shell Programming and Scripting

Not getting expected result

Hi Experts, I have written the below script but its not working as per expectation. My requirement is if this condition ] is satisfied then only check for this condition ] if this also satisfied check for the condition ]. vi p_values.ksh path="/db/ora/files" mode=1 b_days=10... (5 Replies)
Discussion started by: nalu
5 Replies

3. Shell Programming and Scripting

Assigning variable to output gives error with expected result

Hello, I am trying to print out the first string matching query with grep and I need your help. My scenario: Database John F 4433 Street No 88 CA Elisabeth Taylor 7733 Street No 26 ON Jack Nicholson 0133 Green Park No 34 AR John F 2 9399 Southpark No 02D UT test.sh... (6 Replies)
Discussion started by: baris35
6 Replies

4. Shell Programming and Scripting

Help on looping using awk

I have the data like this: PONUMBER,SUPPLIER,LINEITEM,SPLITLINE,LINEAMOUNT,CURRENCY IR5555,Supplier1,1,1,83.1,USD IR5555,Supplier1,1,3,40.4,USD IR5555,Supplier1,1,6,54.1,USD IR5555,Supplier1,1,8,75.1,USD IR5556,Supplier2,1,1,41.1,USD IR5556,Supplier2,1,3,43.1,USD ... (3 Replies)
Discussion started by: jeffreybsu
3 Replies

5. Shell Programming and Scripting

Result of Catching Return Value from Sub_script.sh to Main_script.sh is not as Expected

Main_script.sh #! /bin/sh ./Sub_script.sh rc=$? echo "Return code from Sub_script.sh : $rc" if ; then echo "$rc = 991" echo "" exit 1 elif ; then echo "$rc = 992" echo "" exit 1 elif ; then echo "$rc = 0" echo "" exit 1 fi (2 Replies)
Discussion started by: duddukuri
2 Replies

6. Shell Programming and Scripting

looping in awk

How do I remove last comma? echo "xx yy zz" | awk 'BEGIN{FS=" "}{for (i=1; i<=NF; i++) printf "%s,", $i}'output: xx,yy,zz, required output: xx,yy,zz or (ideally!): xx, yy & zz many thanks in advance! (4 Replies)
Discussion started by: euval
4 Replies

7. Programming

Test program not giving expected result

I have five classes. 2 composition classes,1 aggregation class and 1 dependency class.I have coded all the classes but one of my test program is not giving me the expected result.I have the following classes: TimeStamp Interval (composition of 2 TimeStamps) TimeSheet ( aggregation of many... (3 Replies)
Discussion started by: moraks007
3 Replies

8. UNIX for Dummies Questions & Answers

Help with AWK looping

I'm trying to parse a configuration text file using awk. The following is a sample from the file I'm searching. I can retrieve the formula and recipe names easily but now I want to take it one step farther. In addition to the formula name, I would like to also get the value of the attribute... (6 Replies)
Discussion started by: new2awk
6 Replies

9. UNIX for Advanced & Expert Users

executing script by cron doesnt give me expected result

Hi frnds... I m facing very irritating problem already waisted my 2 days.. I have a following script..( i am pasting only the main code) ftp -ivn 213.194.40.77 <<FTP user $user $password binary cd $FileDir/out lcd $localpath get $file rename $FileDir/out/$file $FileDir/tmp/$file... (1 Reply)
Discussion started by: clx
1 Replies

10. UNIX for Advanced & Expert Users

Looping in awk

Can somebody give me a cleaner way of writing the following script. I was thinking that I could use a loop in the awk statement. It works fine the way it is but I just want the script to be cleaner. #!/usr/bin/sh for r in 0 1 2 3 4 5 6 do DAY=`gdate --date="${r} days ago" +%m\/%d\/%y`... (3 Replies)
Discussion started by: keelba
3 Replies
Login or Register to Ask a Question