Sponsored Content
Top Forums Shell Programming and Scripting Help with reading two input files in awk Post 302573512 by joseamck on Monday 14th of November 2011 07:49:43 PM
Old 11-14-2011
Java Help with reading two input files in awk

Hello,

I'm trying to write an awk program that reads two files inputs.
example,

file 1:
Code:
0.00017835
0.000176738
0.00018811
0.000189504
0.000188155
0.000180065
0.000178991
0.000178252
0.000182513

file 2:
Code:
 1.7871769E-05  1.5139576E-16  1.5140196E-16  1.5139874E-16
 1.7827407E-04  1.6709859E-18  1.6950919E-18  1.6897323E-18
 1.7830577E-04  1.6709414E-18  1.6843205E-18  1.6807697E-18
 1.7833745E-04  1.6709859E-18  1.6843205E-18  1.6807697E-18
 1.7836914E-04  1.6709859E-18  1.6843205E-18  1.6807697E-18
 1.7840082E-04  1.6717005E-18  1.6800867E-18  1.6807697E-18
 1.7843251E-04  1.6717005E-18  1.6800867E-18  1.6807697E-18
 1.7846419E-04  1.6717005E-18  1.6800867E-18  1.6897323E-18
 1.7849589E-04  1.6826009E-18  1.6800867E-18  1.6897323E-18
 1.7852758E-04  1.6891735E-18  1.6843205E-18  1.6897323E-18
 1.7855926E-04  1.6943236E-18  1.6800867E-18  1.6897323E-18
 1.7881277E-04  1.6891735E-18  1.6609087E-18  1.6604721E-18
 1.7884445E-04  1.6891735E-18  1.6565899E-18  1.6604721E-18
 1.7887614E-04  1.6826009E-18  1.6494530E-18  1.6547480E-18
 1.7890782E-04  1.6891735E-18  1.6494530E-18  1.6547480E-18
 1.7893952E-04  1.6943236E-18  1.6494530E-18  1.6547480E-18
 1.7897120E-04  1.6891735E-18  1.6462933E-18  1.6532895E-18
 1.7900289E-04  1.6891735E-18  1.6462933E-18  1.6532895E-18
 1.7903457E-04  1.6826009E-18  1.6462933E-18  1.6532895E-18
 1.7906626E-04  1.6717005E-18  1.6394092E-18  1.6475811E-18
 1.7909794E-04  1.6826009E-18  1.6462933E-18  1.6475811E-18....

where file 2 is much bigger than the file1 and the first column is in descending order.
The problem is that I want every value in file1 to go to the list in file2 and stop until the value in file1 is greater than or equal to that of file2's first column and output the whole row to a new file. Taking in consideration that file2 will contain more data ranging for all values that will be in file1


this is what I have so far but is not workingSmilie
Code:
awk 'NR>=FNR{value = $1} {if(value>$1){print $1};next}' file1 file2 > file3


Last edited by Franklin52; 11-15-2011 at 03:40 AM.. Reason: Please use code tags, thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk reading 2 input files but not getting expected value

I'm reading 2 input files but not getting expected value. I should get an alpha value on file_1_data but not getting any. Please help. >cat test6.sh awk ' FILENAME==ARGV { file_1_data=$0; print "----- 1 Line " NR " -----" $1; next } FILENAME==ARGV { file_2_data=$0; print "----- 2... (1 Reply)
Discussion started by: pdtak
1 Replies

2. Shell Programming and Scripting

Reading an Input file and searching for occurrences WIHOUT SED or AWK

Hi people. I am new to shell scripting, so I need a little help. I want to create a script named that takes an argument as a file, Read the input file and look for occurrences of the current username (say abc.xyz) who is executing the script. On finding an occurrence of the username take that line... (2 Replies)
Discussion started by: kartikkumar84@g
2 Replies

3. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

4. Shell Programming and Scripting

Reading input files

Okay, so I've looked on here and found some similar things, but not exactly what I am looking for. I am working on creating a script that can back up some files, based on the contents of another file - the configuration file. First file contains the files to back up - we'll call this... (1 Reply)
Discussion started by: pdxwarrior
1 Replies

5. Shell Programming and Scripting

Create Multiple files by reading a input file and changing the contents

Being new to this area .I have been assigned a task which i am unable to do . Can any one please help me . Hi I have requirement where i have input file XYZ_111_999_YYYYMMDD_1.TXT and with header and series of Numbers and Footer. I want to create a mutiple output files with each file having a... (2 Replies)
Discussion started by: bhargavkr
2 Replies

6. Shell Programming and Scripting

Reading from standard input with awk

Hello, Could somebody please give me an awk example on how to read from the standard input. It means as the "read" function in Korn shell. Thx in advance ... (3 Replies)
Discussion started by: rany1
3 Replies

7. Shell Programming and Scripting

awk script - reading input lines

Can I do something like, if($0==/^int.*$/) { print "Declaration" } for an input like: int a=5; If the syntax is right, it is not working for me, but I am not sure about the syntax. Please help. Thanks, Prasanna (1 Reply)
Discussion started by: prasanna1157
1 Replies

8. Shell Programming and Scripting

Perl Script Not Reading Input Files Correctly

This is one of the strangest things that's happening to me. I'm writing a new Perl script that is trying to read a file. The file is originally in .mof format, but I also saved the contents into a .txt file. As a simple test, I wrote this: #!/user/bin/perl -w use strict; ... (3 Replies)
Discussion started by: kooshi
3 Replies

9. Shell Programming and Scripting

awk- reading input file twice

Hello, I've been trying to come up with a solution for the following problem; I have an input file with two columns and I want to print as an output the first column without any changes but for the second column, I want to divide it by its last value. Example input: 1 9 2 10 3 11 4 12 5... (14 Replies)
Discussion started by: acsg
14 Replies

10. Open Source

Splitting files using awk and reading filename value from input data

I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies
XZDIFF(1)							     XZ Utils								 XZDIFF(1)

NAME
xzcmp, xzdiff, lzcmp, lzdiff - compare compressed files SYNOPSIS
xzcmp [cmp_options] file1 [file2] xzdiff [diff_options] file1 [file2] lzcmp [cmp_options] file1 [file2] lzdiff [diff_options] file1 [file2] DESCRIPTION
xzcmp and xdiff invoke cmp(1) or diff(1) on files compressed with xz(1), lzma(1), gzip(1), or bzip2(1). All options specified are passed directly to cmp or diff. If only one file is specified, then the files compared are file1 (which must have a suffix of a supported com- pression format) and file1 from which the compression format suffix has been stripped. If two files are specified, then they are uncom- pressed if necessary and fed to cmp(1) or diff(1). The exit status from cmp or diff is preserved. The names lzcmp and lzdiff are provided for backward compatibility with LZMA Utils. SEE ALSO
cmp(1), diff(1), xz(1), gzip(1), bzip2(1), zdiff(1) BUGS
Messages from the cmp(1) or diff(1) programs refer to temporary filenames instead of those specified. Tukaani 2009-07-05 XZDIFF(1)
All times are GMT -4. The time now is 02:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy