The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
retrieved multiple lines on multiple places in a file dala Shell Programming and Scripting 8 03-14-2008 12:28 PM
Model-Based Assurance of Security Controls iBot UNIX and Linux RSS News 0 02-07-2008 02:20 PM
How to choose Multiple process or Multiple threads? ashleykumar IP Networking 0 04-10-2006 03:30 AM
Solaris 10 Resource Controls here2learn UNIX for Dummies Questions & Answers 2 01-25-2006 11:30 AM
Print Controls for DG Unix baddi UNIX for Dummies Questions & Answers 0 02-18-2005 02:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-23-2008
Registered User
 

Join Date: Jun 2005
Posts: 47
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????
Reply With Quote
Forum Sponsor
  #2  
Old 01-23-2008
Registered User
 

Join Date: Jun 2005
Posts: 47
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???
Reply With Quote
  #3  
Old 01-23-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
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)
Reply With Quote
  #4  
Old 01-23-2008
Registered User
 

Join Date: Jun 2005
Posts: 47
It works great!!! Thanks
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0