Help With Backward grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help With Backward grep
# 1  
Old 11-16-2011
Wrench Help With Backward grep

hey, i got 2 files with the following content:

file1:
Code:
LOCAL_GSK1
50:01:24:80:45:f1:15:23
50:01:24:81:45:f1:15:23
50:01:24:82:45:f1:15:23
50:01:24:83:45:f1:15:23
LOCAL_GSK2
50:01:24:82:00:9c:d7:a7
50:01:24:82:01:bc:d7:a7
50:01:24:82:02:dc:d7:a7
50:01:24:82:03:fc:d7:a7
LOCAL_GSK3
50:01:24:80:45:39:a7:0b
50:01:24:81:45:39:a7:0b
50:01:24:82:45:39:a7:0b
50:01:24:83:45:39:a7:0b
LOCAL_GSK4
50:01:24:80:45:c1:3b:33
50:01:24:81:45:c1:3b:33
50:01:24:82:45:c1:3b:33
50:01:24:83:45:c1:3b:33
REMOTE_GSK1
50:01:24:80:45:bd:3e:5f
50:01:24:81:45:bd:3e:5f
50:01:24:82:45:bd:3e:5f
50:01:24:83:45:bd:3e:5f

file2:
Code:
10:00:00:05:1e:03:65:59
10:00:00:05:1e:03:65:59
50:00:09:73:10:03:71:04
50:00:09:73:10:03:71:05
50:00:09:73:10:03:71:00
50:00:09:73:10:03:71:01
50:01:24:80:45:bd:3e:5f
50:01:24:81:45:bd:3e:5f
50:01:24:80:45:31:ad:63
50:01:24:81:45:31:ad:63
50:01:24:80:45:69:80:fb
50:01:24:81:45:69:80:fb
50:01:24:80:45:39:a7:0b
50:01:24:81:45:39:a7:0b
21:00:00:24:ff:30:35:7b
21:00:00:24:ff:30:35:7a
21:00:00:24:ff:30:35:6a
21:00:00:24:ff:30:35:6b
21:00:00:24:ff:30:35:7e
21:00:00:24:ff:30:35:7f

what i need is to search in file1 and compare it to file2
if a match was found then
print the match found and the group name
for example searching for:
file1
Code:
50:01:24:81:45:bd:3e:5f
50:01:24:81:45:39:a7:0b

will print this from file2
Code:
REMOTE_GSK1
50:01:24:81:45:bd:3e:5f
LOCAL_GSK3
50:01:24:81:45:39:a7:0b

any help would be appreciated Smilie
thank u all.
# 2  
Old 11-16-2011
I get a different result, could you check if your example output is correct with respect to the posted content?

Code:
awk 'END { 
  if (f) 
    print f 
    }
NR == FNR { 
  f1[$1] 
  next
  }
/^[^0-9]/ { 
  if (f) { 
    print f 
    f = null 
    } 
  g = $0 
  }
$1 in f1  { 
  f = f ? f RS $1 : g RS $1 
  }' file2 file1

This User Gave Thanks to radoulov 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

Backward compatibility issue with GNU bash, version 4.3.42(5)

Hi, I have made a snake game on below bash version. But it is not backward compatible. Can someone suggest a version which is most commonly used and is backward compatible so that i can change my code and share again? I have attached the game script. If someone can run it please also suggest... (5 Replies)
Discussion started by: amit14august
5 Replies

2. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

3. Programming

Backward compatibility in python

Actually I have installed python 3.2. It seems there are a lot of synta variance between 2.2 and 3.2. Is it possible to run a script in 2.2 without actually installing 2.2. But I have installed 3.2. and also is it possible to access the 2.2 shell in 3.2 version. I am naive in python . Please... (1 Reply)
Discussion started by: pandeesh
1 Replies

4. Shell Programming and Scripting

backward string cut

I need only the last .ko files to be stripped from the whole result., ie libiscsi2.ko, scsi_transport_iscsi2.ko etc.. kernel/drivers/scsi/libiscsi2.ko kernel/drivers/scsi/scsi_transport_iscsi2.ko kernel/drivers/scsi/scsi_transport_iscsi.ko kernel/fs/nls/nls_utf8.ko... (4 Replies)
Discussion started by: anilcliff
4 Replies

5. SCO

sco unix backward compatibility on "max open file per process"

Hi How to increase maximum number of open file in "sco xenix binary" running in "sco unix openserver 5.0.7" ? I have changed "NOFILES" kernel parameter to 512, but xenix binray can't open more than 60. tnx (4 Replies)
Discussion started by: javad1_maroofi
4 Replies

6. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

7. Shell Programming and Scripting

forward/backward capable prompt

Hi, I would like to construct an interactive prompt for a series of bash shell scripts. This prompt will ask the user a series of questions, and the answers will determine which scripts are run, and in which order. I am familiar with the "read" command, and have successfully constructed a... (2 Replies)
Discussion started by: msb65
2 Replies

8. UNIX for Advanced & Expert Users

Substitute single backward-slash with the double backward-slash

Hi, I have a path like this c:\test\sample\programs, i need to change thiis to c:\\test\\sample\\programs. How to perform this? I tried tr command but it didn't help me. Thanks Vijayan (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

9. UNIX for Dummies Questions & Answers

Find the current cursor word in backward

hello, i'm using the vi editor (not vim) and my main use in it is for C++ programming. After working on Visual Studio 2005 the auto-complete looks like paradise now... so i'm trying to find a way to have auto-complete also in the vi. i cant install vim and use the ctrl+P. i need to find a way... (1 Reply)
Discussion started by: Malbinir
1 Replies
Login or Register to Ask a Question