![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compare Files and Output Difference | Joesgrrrl | UNIX for Dummies Questions & Answers | 2 | 12-13-2008 09:51 PM |
| Compare two files and output diff to third file | altamaha | Shell Programming and Scripting | 8 | 09-25-2008 10:42 AM |
| Compare 2 files and output result in pop up window | hongsh | UNIX for Dummies Questions & Answers | 2 | 05-23-2008 09:50 AM |
| Compare 2 files and give uniq output | rauphelhunter | Shell Programming and Scripting | 1 | 05-12-2008 04:47 PM |
| compare two col from 2 files, and output uniq from file 1 | pp56825 | Shell Programming and Scripting | 2 | 01-10-2008 11:10 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Compare 2 files and send output to other
Hi,
In File1.txt I have text like: 23AA3424DD23|3423ff25sd5345| and so on In File2.txt I have similar text as File1, but with ",": 23aa3424dd23,192.168.1.100, and so on I wan to remove the pipes from File1 and select 5 fields, then remove "," from File2.txt and select 2 fields (IP's and MAC's), compare (line by line) the MAC's from File2 with the ones in File1, if equal then print those 5 fields from File1 with the correspondent IP from File2 in Final.txt I can't figure it out using awk with variables, I'm using files: Code:
awk -F"|" '{print $1, $2, $4, $5, $10}' File1.txt > temp1.txt
awk -F"," '{print $1, $2}' File2.txt|tr '[:lower:]' '[:upper:]' > temp2.txt
egrep -f File2.txt File1.txt > Final.txt
I think I'm being clear ![]() |
|
||||
|
Without knowing a full example of text here is an option.
You could wrap it in a loop: Code:
awk -F"|" '{print $1, $2, $4, $5, $10}' File1.txt|tr '[:lower:]' '[:upper:]' > temp1.txt
awk -F"," '{print $1, $2}' File2.txt|tr '[:lower:]' '[:upper:]' > temp2.txt
for MAC in `cat temp1.txt`
do
MAC2=`cut -d" " -f1 temp2.txt`
IP=`cut -d" " -f2 temp2.txt`
if [ "$MAC" = "$MAC2" ] ; then
echo "`cat temp1.txt` - $IP" >> Final.txt
fi
done
|
|
||||
|
In File1.txt I have text like:
23AA3424DD23|3423ff25sd5345| and so on In File2.txt I have similar text as File1, but with ",": 23aa3424dd23,192.168.1.100, and so on If the second field from File2.txt matches the tenth field from File1.txt then write that line and append the correspondent IP from File2.txt in Final.txt Edited: For better understanding. Last edited by cameleon; 04-22-2009 at 12:53 PM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|