I am working on solaris unix.
I have two files:
> cat temp
2
8
6
> cat temp2
1
2
3
4
5
6
7
8
9
>
Now i need all the lines in temp2 which are present in temp:
I came across this and tried the below command.
> nawk 'FNR==NR{a[$0];next}($1 in a)' temp temp2
2
6
8
>
and this worked perfectly.
Then i also saw the the way to use join here
where in it says(and also the man page) that “By default the join command matches the files on the first fields when we do not specify the field numbers explicitly”
So i thought that if i give join temp temp2 i will get
2
6
8
but here is waht i got!
> join temp temp2
2
8
>
Can anybody tell me why 6 is missing here if by default join matches the first column?
You need to sort files before running
joinin order to match them.It can be done using:
And my output is: