Awk: Comparing arguments with in line values of file and printing the result
I need to develop a script where I will take two date arguments as parameter date1 and date2 which will in format YYYYMM.
Below is the input file say sample.txt.
sample.txt will have certain blocks starting with P1.
Each block will have a value 118,1:TIMESTAMP.
I need to compare the arguments date1 and date2 with this TIMESTAMP and if it is between date1 and date2 then I want this entire block starting from P1 to start of next P1 to be copied in a new file say output.txt.
Since the input files will be very large I want to develop in awk and not shell.
---------- Post updated at 04:54 AM ---------- Previous update was at 04:52 AM ----------
This one relies on the empty line block separator trailing the P1 blocks:
Thanks Rudic. It works. Can you explain a little about your awk line. Does it work block by block or line by line ?
Sorry for asking such a basic question but I am very new to awk.
Last edited by garvit184; 06-23-2014 at 08:15 AM..
My file (the output of an experiment) starts off looking like this,
_____________________________________________________________
Subjects incorporated to date: 001
Data file started on machine PKSHS260-05CP
**********************************************************************
Subject 1,... (9 Replies)
First I'd like to apologize if I opened a thread which is already open somewhere.
I did a bit of searching but could quite find what I was looking for, so I will try to explaing what I need.
I'm writing a script on our server, got to a point where I have two files with results. Example:
File1... (6 Replies)
Hi All
I had requirement where I need to re-order columns in a file by using a control file.
here is the ctrl file
c1
c2
c3
source file
c3 | c1 | c2
a | b| c
I should create output file based on the ctrl file columns
o/p should look like this
c1 | c2 | c3
b| c|a
I wrote some... (9 Replies)
Hi,
I have two text files with matching first columns. Some of the values in the second column do not match. I want to write a script to print out the rows (only the first column) where the values in the second column do not match.
Example:
Input 1
A 1
B 2
C 3
D 4
Input 2
A 2
B 2... (6 Replies)
I am trying to delete lines in archived Apache httpd logs
Each line has the pattern:
<ip-address> - - <date-time> <document-request-URL> <http-response> <size-of-req'd-doc> <referring-document-URL>
This pattern is shown in the example of 6 lines from the log in the code box below. These 6... (1 Reply)
I have a C++ program. I read command line arguments, but if the value is not supplied, I default or make a calculation. Let's say I set it to a default value.
I can code this in several ways. Here I show three ways. What would be the best way for maintaining this code? The program will get very... (2 Replies)
I have two text files where the first three columns are exactly the same. I want to compare the fourth column of the text files and if the values are different, print that row into a new output file. How do I go about doing that?
File 1:
100 rs3794811 0.01 0.3434
100 rs8066551 0.01... (8 Replies)
Dear all,
I am using awk in a bash script to extract a list of x y z coordinates from a file such as:
%BEGIN 3D-SPACE COORDINATES
0.2085627338147950 0.2471306816410478 0.2085627338147950
0.1242549179185660 0.2755539793525220 0.4147884486606120
0.2030669560265720 ... (6 Replies)