I have gotten a script that helps me to parse, read, and output the data in a specific format, over on (Unix and Linux) Ubuntu 16. Although I am not getting any errors but the script is NOT producing the result that I expect.
What the script does? I have a large input data file data.txt (see below); for every timestamp, I need to find the nearest time match 5 minutes later and the value on column 4 and then print both in two new columns.
The logic for the match is - Calculate the time 5 minutes later from the current time stamp, now get the value closes to this time within a 2 mins limit in either direction, for example lets say time now is 00:00:00.000 get the value no sooner that 00:03:00.000 and no later than 00:07:00.000, else print NA NA. Not to mention that the final matches will all show NAs.
for example for
I need to find the best time available 5 minutes later (i. e. approximately)
So the output line must be
Please note that there are no exact time matches here, that is why only the nearest match is found. Also the code should seamlessly work when the date changes from 2018-02-16 to 2018-02-17.
However, this script is not outputting things properly. The expected output should look like this
This is how I run the script from the command line:
output of the following command:
it's giving me this instead: i. e. it prints the four lines of the input file unsorted.
your proposed changes
as well as Replacing
is printing only "NA NA" in the last two columns it's not matching anything
I request you run the script in your Ubuntu or UNIX machine in debug mode and see if you can replicate the results.
Last edited by delbroooks; 03-21-2018 at 06:28 PM..
Reason: tried the suggested changes
. . . find the best time available 5 minutes later (i. e. approximately)
What is "approximately 5 minutes later"? Within 5 min? Beyond 5 min? 10 sec / 30 sec / 100 sec within / beyond?
Quote:
. . . The expected output should look like this
Why the 612 ms, not the 611 ms entry?
Quote:
You shebang might not work as it seems to be a relative path.
Quote:
Is this ms precision to eliminate duplicate indices? ms wouldn't make sense if you're dealing with approximate 5 min?
Quote:
.
.
.
With min = 0 and difference ALWAYS positive, the if branch will NEVER be entered. So - no surprise matchfor is undefined / uninitialized:
Quote:
Would you mind to take a step back and rephrase your requirements? Like "For any given record take its time stamp, add five minutes, and from there find the line in the data file with the smallest absolute delta time and print it as a suffix to the actual line"
@RudiC I have rephrased the question above. Please see the logic of the match. Basically there is 2 minutes time window on either side to find a match, if none found it prints NAs
To your question weather the code runs- the answer is absolutely yes the code runs. May I request to you copy and paste the code as well as the data.txt file in your ubuntu terminal and run it to see if the results are replicated.
You could try this script. I believe your OS should come with GNU awk by default so it's much more efficient to use the mktime() feature to convert these times.
Last edited by Chubler_XL; 03-22-2018 at 12:22 AM..
This User Gave Thanks to Chubler_XL For This Post:
Hi,
I have a script below that is running ssh <host> <command> on some servers.
Below is more or less the script. I have to modify it somehow to get rid of the 'confidential' hostnames
check_log.bash
#!/bin/bash
#
myPID=$$
parse_log ()
{
sub="parse_log"
host=${1}
... (2 Replies)
Hi All,
I have below simple shell script in cloudera quick start vm cenos 6 which copy file from source to destination.
# file_copy.sh
source_dir = ${source_dir}
target = ${target_dir}
cp source_dir target
and my parameter file is like below
#parameter_file.txt
source_dir =... (4 Replies)
Hi Experts,
Need your kind help with gsub awk.
Below is my pattern:"exec=1_host_cnt=100_dup=4_NameTag=targetSrv_500.csv","'20171122112948"," 100"," 1"," 1"," 4","400","","",
" aac sample exec ""hostname=XXXXX commandline='timeout 10 openssl speed -multi 2 ; exit 0'"" ","-1","-1","1","... (6 Replies)
Following one line of awk code removes first 3 characters from each line but when I run the same code on another linux platform it doesn't work and only prints blank lines for each record. Can anyone please explain why this doesn't work? (31 Replies)
Dear all,
I had script which used to work, but recently it is not working as expected.
I have command line in my shell script to choose the following format from the output_elog and perform some task afterwards on
As you see, I want all numbers in foramt following RED mark except for... (12 Replies)
Hi,
I have prepared a script and trying to execute it but not getting expected output. Could you please help and advise what is going wrong.
"If else" part in below script is not working basically.
I am running it on HP-UX.
for i in slpd puma sfmdb
do
echo "******\t$i\t*******"
echo... (10 Replies)
Hi!
Been working on a script and I've been having a problem. I've finally narrowed it down to this variable I'm setting:
servername=$(awk -v FS=\/ '{ print $7 } blah.txt | sed 's\/./-/g' | awk -v FS=\- '{print $1}')"
This will essentially pare down a line like this:
... (7 Replies)
I am facing some strange problem.
I know, there is only one record in a file 'test.txt' which starts with 'X'
I ensure that with following command,
awk /^X/ test.txt | wc -l
This gives me output = '1'.
Now I take out this record out of the file, as follows :
awk /^X/ test.txt >... (1 Reply)
Hello.
Consider the following magic words:
# ls `which adduser`
ls: /usr/sbin/adduser: No such file or directory
#
Hmmm...
Then:
# ls /usr/sbin/adduser
/usr/sbin/adduser
#
Now what?
Unforunately this little sniippet is used in my debian woody server's mysql pre install script.... (2 Replies)