Operating System - HP-UX
1755772 Members
2593 Online
108838 Solutions
New Discussion юеВ

Re: problem with awk script..

 
SOLVED
Go to solution
spex
Honored Contributor

Re: problem with awk script..

Hi,

Based on the grep error message you provided, it doesn't appear you're using HP-UX (SunOS, perhaps?).

If that's the case, try:

$ /usr/xpg4/bin/grep -f file2 file1

or:

$ grep `cat file2` file1

PCS
amonamon
Regular Advisor

Re: problem with awk script..

sandman it works..but I do not understand a code..I never worked with join..I am trying to gigure it in man join..but it goes slow..if U could explain little..

grep 'cat file1' file2 does not work..

thanks friends..

cheers..
Sandman!
Honored Contributor

Re: problem with awk script..

The join(1) example was based on the input you had provided, i.e.

file1:

232323|2007|12|09
343434|2007|12|09
565656|2007|12|09
898989|2007|12|09
090909|2007|12|09
..
..

file 2:

232323
343434
343433
343432
343431
..
..

# join -1 1 -2 1 -t'|' -o 1.1 1.2 1.3 1.4 file1 file2

The join(1) example above "glues" the two files (file1 and file2) together on the fields that are common to both...which is field 1 as shown by command line options -> "-1 1 -2 1".

The field separator is the pipe character -t'|' (needs to be escaped or quoted as it has special meaning to the shell, and the output should consist of all fields from the first file -> "-o 1.1 1.2 1.3 1.4".

imho...not sure why the grep command by JRF is not working for you. It works perfectly on my HP-UX box. Are you using HP-UX or some other variant?

~hope it helps
Peter Nikitka
Honored Contributor

Re: problem with awk script..

Hi,

of course JRF's solution works for Solaris as well - but you have to use the POSIX compliant binary:

/usr/xpg4/bin/grep -f file2 file1

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
amonamon
Regular Advisor

Re: problem with awk script..

thanks..a lot

yes /usr/xpg4/bin/grep -f file2 file1
works fine on my solaris..

thanks guys,

cheers,