The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: Search for string on line then compare numbers! Crypto Shell Programming and Scripting 2 01-22-2008 01:50 AM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM
Compare two arrays in sh or compare two fields rijeshpp Shell Programming and Scripting 0 10-31-2007 02:47 AM
Search--Compare--Redirect satheesh_color Shell Programming and Scripting 1 09-27-2006 01:21 AM
Advanced Search Problems.. Search by User Name Neo Post Here to Contact Site Administrators and Moderators 1 05-19-2003 12:28 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2005
netrom netrom is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 9
Lightbulb Search, compare or?

I found this very helpful forum and there are very friendly people, I have a small request.


I use AIX Unix and would like to know if there's a simple way how to do a kind of compare between two files.

I have 2 text files, let's name them file1 and file2.

What I need:

I want to read line by line file1 - certain field or better 2 fields of the file1 and look up the information in the file2.

To be more descriptive: I'd like to extract field1 at position 10-15 and field2 at position 25-31 from file1 and search or find if the same information is somewhere inside the file2. When no, I'd like to output the field1 & field2 off the file1 doesn't exit in file2.

let's say file1 contains something like:

123232 3232 2323 2323123123213 trterert

and file2 e.g.

123232 3232 2323 2323123123213 XXXXXXXX

and let's say I want 123232 & trterert from file1 to be searched in file2 ==> I get an "error" because the script would find only 123232 and not trterert.....

I'd be more than happy if someone can help me out or recommend a link or appropriate command or script.

I just need to check some record(s) in one file - and if they're available in the other file...

Please!

Thanks a lot!

Marian
  #2 (permalink)  
Old 09-28-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,748
Code:
# put the first column and 
#   fifth column into a file, 
#   make it unique values

awk '{ print $1,$5 } ' file1 | sort -u > patternfile
#  loop thru the patterns from file1 
#  look for them in file2, print patterns if not found
while read pattern1 pattern2
do
    if [ ${#pattern2} -eq 0 ]; then  # skip when pattern2 isn't there
        continue
    fi
	grep "$pattern1" file2 | grep -q "$pattern2"
	if [ $? -ne 0 ]; then
		echo "$pattern1" "$pattern2"
	fi
done < patternfile
I'm assuming the fields from file1 can be anywhere on the line in file2.
  #3 (permalink)  
Old 09-29-2005
netrom netrom is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 9
Thanks Jim,

what if I want to extract not columns but certain positions from file1? I mean I don't have any columns resp. tabs?

I'd like to choose e.g. positions 5-9 (let's say string1) and 23-35 (string2) from file1 and then search for it in file2 (whatever line with both string1 and string2 - doesn't matter at which position).

I hope you can 'fix' the script to reflect this

Many thanks for you kind help!

Marian
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0