![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
|
|
||||
|
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|