Bash or awk script to solve this problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash or awk script to solve this problem
# 1  
Old 09-15-2010
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.

I have two files, file1 is in the format:
time position
HTML Code:
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
...
Then the second file (file2) is in the format:
time measurement
HTML Code:
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:
HTML Code:
906.00001 18
909.28645 20
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!!!!
# 2  
Old 09-15-2010
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:
Code:
awk 'NR==FNR{if($NF=="in"){a[$1]}next} $1 in a' file1 file2

# 3  
Old 09-15-2010
Code:
awk -F"[.| ]" 'NR==FNR{a[$1]=$3;next} a[$1]=="in" ' file1 file2

903.14356 12
906.00001 18
909.28645 20

This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 09-15-2010
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!!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash/awk script problem

Hi, I have 100 files containing different values in single column, I want to split those files in two separate files (file2 and file3) based on average value of first column of each file, for those files I am working on the following script #bin/bash for memb in $(seq 1 100) do awk... (4 Replies)
Discussion started by: dsp80
4 Replies

2. Shell Programming and Scripting

I have a bash script and tried very hard but i couldn't solve it please help

please can you help me with this script ( very very important ) what I'm trying is to write program that accepts list of user as its argument 1- If a user or more are given as arguments, the script should reset files permissions as follows: a. Directory ~/share to 750 (if it exists). b. All... (10 Replies)
Discussion started by: testman84
10 Replies

3. Shell Programming and Scripting

Unknown Problem. I really want your help to solve this!

Take a look on this code: #!/bin/sh currentpath=`pwd` if ; then #Normal user if ; then "$currentpath"/.cleaner else ./runit fi else #Root user if ; then rm -r /some fi mkdir /some cd /home/ echo "`ls --group-directories-first -1`" > /some/allusers cat /some/allusers | sed 's/... (17 Replies)
Discussion started by: hakermania
17 Replies

4. UNIX for Advanced & Expert Users

Help! SHELL or AWK script - only the masters of the forum will solve

Hello everybody! I have no experience with shell Programmer, but I need to compare 02 files. Txt and generate an output or a new file, after the comparisons. see: If the column 1 of file1 is equal to column 1 of file2, and column 3 of file2 contains the column 4 of file1, output: column1... (4 Replies)
Discussion started by: He2
4 Replies

5. UNIX for Advanced & Expert Users

how would you solve this problem?

I have a file process.txt I wanted to just grab data in "process" column. Name process process_id status Adminserver adminserver 22669 Running Browser Engine browserengine ... (7 Replies)
Discussion started by: soemac
7 Replies

6. Programming

Can any one solve this Problem...!!!

Try to solve this.....It's a nice program..... #include<stdio.h> void change() { /*Write something in this function so that the output of printf in main function should give 5 . Do not change the main function */ } void main() { int i=5; change(); (9 Replies)
Discussion started by: Baba B. Saheb
9 Replies

7. UNIX for Advanced & Expert Users

can't solve that problem [PLEASE HELP]

well, my internet brakes down every day because of my server, i don't have troubles with RAM or anything i think... that problem started since i am running an unrealircd server... well, my internet brakes down and when i try to access the inside ip from the server on http port 80, it says that:... (2 Replies)
Discussion started by: AiRkO
2 Replies

8. Programming

How can I solve this problem?

I'm now designing a server application which can serve large number of clients' request. I've a question to ask, that is, main process will block when invoke the "accept" function, if a client request comes, main process should be separated into 2 processes by invoking "fork" function, the parent... (4 Replies)
Discussion started by: acqy
4 Replies
Login or Register to Ask a Question