Bash or awk script to solve this problem

Hi everybody!

I have written some awk scripts that return me some results I need to process. At the moment I use openOffice to process them, but I am trying to find a more efficient solution using possibly a bash or awk script.

[LEFT]I have two files, file1 is in the format:
time position[/LEFT]

900.07552 out
900.21297 out
901.53535 out
902.24243 out
903.76858 in
903.80986 in
904.68645 in
905.75785 in
906.13636 in
907.35424 out
908.45325 out
909.23456 in
910.24322 out
911.54478 out
...

[LEFT]Then the second file (file2) is in the format:
time measurement[/LEFT]

896.72412 23
899.84956 12
900.93412 23
903.14356 12
906.00001 18
909.28645 20
910.83635 11
...

I'd like to obtain the lines in file2 correspondent to the time instants in which the position is "in", for example:

906.00001 18
909.28645 20

[LEFT]Since these files are very long and have variable sizes, I find quite uncomfortable to use openoffice, so I am trying to write a script but I am very new to scripts and I have some problems in comparing lines.. any idea?
Thank you very much!!!![/LEFT]

With OpenOffice? Anyway, I don't see any relationship between the first file and the desired output but if I understand your question, this should do the job:

awk 'NR==FNR{if($NF=="in"){a[$1]}next} $1 in a' file1 file2
awk -F"[.| ]" 'NR==FNR{a[$1]=$3;next} a[$1]=="in" ' file1 file2

903.14356 12
906.00001 18
909.28645 20

1 Like

Yes, I'm so sorry I deleted the first line in the desired output while putting the tag to format it!
Thank you very much both for your help!!