hi guys!!
i have two files..file1 with data
111
222
333
444
and file2 with data
111,home
222,hotel
333,caffetaria
444,pool
555,restuarant
i want to know script that compares file1 with file2 for only first feild and give me result as
111,home
222,hotel
333,caffetaria
am new to linux script!!
can any one plz help!!
Actually, based on your data the result should be: 111,home
222,hotel
333,caffetaria
444,pool
One way is to read the first datafile into an associative array and then read the other file and see if field 1 is in the array::#!/bin/bash awk ' BEGIN { FS="," while ( getline < "datafile1" > 0 ) myarr[$0]=$0 } { if($1 in myarr) print $0 } ' datafile2