awk with multiple controls


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk with multiple controls
# 1  
Old 01-23-2008
awk with multiple controls

Hi guys,

I have a file which is like this

Code:
020-10136044 07-11-26 15:31:22 TRXRMP TCMAGT82TCM		  LHFE1G76006AK3
020-10136044 07-11-26 15:31:25 CIMFSU TCMAGT82TCM	      RCS LHFE2G6H006AGP
020-10136055 07-11-26 08:43:21 TRXRMP TCMAGT82TCM		  LHFE2G6H005QV9
020-10136055 07-11-26 15:31:27 TRXRMP TCMAGT82TCM		  LHFE1G76006AKG
020-10136055 07-11-26 15:31:31 CIMFSU TCMAGT82TCM	      RCS LHFE2G6H006AH8
020-10136066 07-11-26 08:41:20 TRXRMP TCMAGT82TCM		  LHFE2G6H005QSI
020-10136066 07-11-26 15:32:16 CIMFSU TCMAGT82TCM	      RCS LHFE2G6H006AHN
020-10136066 07-11-26 15:32:16 TRXRMP TCMAGT82TCM		  LHFE1G76006ALB
020-10136070 07-11-26 15:27:32 TRXRMP TCMAGT82TCM		  LHFE1G76006AC6
020-10136070 07-11-26 15:30:28 TRXRMP TCMAGT82TCM		  LHFE1G76006AIM
020-10136070 07-11-26 15:30:29 CIMFSU TCMAGT82TCM	      RCS LHFE1G76006AIO
020-10136081 07-11-26 15:30:37 CIMFSU TCMAGT82TCM	      RCS LHFE2G6H006AFP
020-10136092 07-11-26 08:51:17 TRXRMP TCMAGT82TCM		  LHFE1G76005RCM
020-10136092 07-11-26 15:31:17 CIMFSU TCMAGT82TCM	      RCS LHFE2G6H006AG0
020-10136092 07-11-26 15:31:18 TRXRMP TCMAGT82TCM		  LHFE2G6H006AG3
020-10136103 07-11-28 15:08:53 CIMFSU TCMAGT82TCM	      RCS LHFE1G77000W02
020-10136114 07-11-28 07:52:26 TRXRMP TCMAGT82TCM		  LHFE1G770007P9
020-10136114 07-11-28 15:12:57 CIMFSU TCMAGT82TCM	      RCS LHFE2G6I0017M

The file is really big and I want to filter those lines where the first field and the third field are the same but the fourth field in these 2 lines is different. When this is happening the lines are one after the other. You can see an example to understand with the lines in red color.
So actually I need in my output only the lines marked with red.

My first thought is with an awk to create a double for loop but I am still having huge trouble to implement this.

Can somebody help????
# 2  
Old 01-23-2008
I thought of the following script but it seems that I have a syntax error.

Code:
awk -F" " '($1==prev1)&&($2==prev2)&&($3==prev3)&&($4!=prev4){print; prev1=$1 prev2=$2 prev3=$3 prev4=$4}' test.txt

Any ideas???
# 3  
Old 01-23-2008
Code:
awk '{a[NR]=$1;b[NR]=$3;c[NR]=$4;t[NR]=$0} END {for (i=2;i<=NR;i++){if ( a[i-1]~a[i]&&b[i-1]~b[i]&&c[i-1]!~c[i] ){print t[i-1];print t[i]}}}' infile

should work...

(use nawk or /usr/xpg4/bin/awk for solaris)
# 4  
Old 01-23-2008
It works great!!! Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Solaris

What is the Solaris OS deamon which controls Library?

Hi All, What is the Solaris OS deamon which controls the Libraries? Regards, Rakesh. (2 Replies)
Discussion started by: rakesh.413
2 Replies

2. Programming

Why is subclassing not allowed for many of the SWT Controls?

hi guys, Why is subclassing not allowed for many of the SWT Controls? But Eclipse itself creates our Shell classes in this way (inheriting from Shell) and then overriding checkSubclass() with empty body. So is it good(safe) that we do this way? I have two shells (Shell_1, Shell_2). Shell_1 is... (0 Replies)
Discussion started by: majid.merkava
0 Replies

3. UNIX for Dummies Questions & Answers

Solaris 10 Resource Controls

I've always been accustomed to setting certain kernel parameters in the /etc/system file. However, with Solaris 10, they have created the resource control utility to set these values. I've set the value for project.max-shm-memory to 4gb with the following command: prctl -n... (2 Replies)
Discussion started by: here2learn
2 Replies

4. UNIX for Dummies Questions & Answers

Print Controls for DG Unix

Hi: We are trying to use UNIX Print Controls for our ERP Package. We have currently set up escape codes on some ERP Users for specific reports. However we would like to try to control this using DG Unix functionality that allows different printers to be set up for one physical printer. Example,... (0 Replies)
Discussion started by: baddi
0 Replies
Login or Register to Ask a Question