Sponsored Content
Top Forums Shell Programming and Scripting awk matching script not working as expected Post 303014911 by RudiC on Friday 23rd of March 2018 08:14:44 AM
Old 03-23-2018
For your first problem, try - based on the assumption that there's only few time stamps with duplicate seconds and norrmally large gaps in between - this simpler approach, which eliminates the need for a system call to date by adding the epoch time to every line upfront:

Code:
paste <(date +"%s" -f<(cut -d" " -f1,2 data.txt)) data.txt | awk '
$1 in LN        {$1++
                }
                {TM[NR] = $1
                 sub ($1 ".", _)
                 LN[TM[NR]] = $0
                }
END             {for (n=1; n<=NR; n++)  {TMP = TM[n] + 300
                                         DT  = 0
                                         for (SEC=0; SEC<120; SEC++)    {if ((TMP + SEC) in LN) DT = +SEC
                                                                         if ((TMP - SEC) in LN) DT = -SEC
                                                                         if (DT) break
                                                                        }
                                         OUT = LN[TMP+DT]
                                         sub  (/farads./, _, OUT)
                                         $0 = LN[TM[n]] OFS (OUT?OUT:"NA NA")
                                         print
                                        }
                }
'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

which not working as expected

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)
Discussion started by: osee
2 Replies

2. Shell Programming and Scripting

awk not working as expected with BIG files ...

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)
Discussion started by: videsh77
1 Replies

3. Shell Programming and Scripting

Var substitution in awk - not working as expected

countA=`awk '/X/''{print substr($0,38,1)}' fName | wc -l` countB=`wc -l fName | awk '{print int($1)}'` echo > temp ratio=`awk -va=$countA -vc=$countB '{printf "%.4f", a/c}' temp` After running script for above I am getting an error as : awk: 0602-533 Cannot find or open file -vc=25. The... (3 Replies)
Discussion started by: videsh77
3 Replies

4. Shell Programming and Scripting

bash variable (set via awk+sed) not working as expected

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)
Discussion started by: creativedynamo
7 Replies

5. Shell Programming and Scripting

Script not working as expected

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)
Discussion started by: sv0081493
10 Replies

6. Shell Programming and Scripting

awk not working as expected in script

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)
Discussion started by: emily
12 Replies

7. Shell Programming and Scripting

awk command not working as expected

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)
Discussion started by: later_troy
31 Replies

8. Shell Programming and Scripting

awk gsub not working as expected

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)
Discussion started by: pradyumnajpn10
6 Replies

9. UNIX for Beginners Questions & Answers

Passing Arguments to shell script from file is not working as expected.

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)
Discussion started by: Narasimhasss
4 Replies

10. UNIX for Beginners Questions & Answers

Why this script is not working as 'expected' when doing ssh with while read ... really confused?

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)
Discussion started by: newbie_01
2 Replies
GETDATE(1)							   User Commands							GETDATE(1)

NAME
getdate - AME SYNOPSIS
[-dv][-n dec][-f format] [ra dec sys] itype2otype [date and/or time] DESCRIPTION
Convert date and time between various formats [-dv][-n dec][-f format] itype2otype @file itype: nfd=ISOFITS fd=FITS, dt=yyyy.mmdd, hr=hh:mm:ss, deg=dd:mm:ss jd=Julian Date, mjd=Modified Julian Date hjd=Heliocentric Julian Date, mhjd=Modified HJD ep=epoch, epj=Julian epoch, epb=Besselian epoch lt=local time, ut=UT, ts=seconds since 1950-01-01 now=current time, ang=fractional degrees otype: fd=FITS, dt=yyyy.mmdd, jd=Julian Date, mjd=Modified Julian Date hjd=Heliocentric Julian Date, mhjd=Modified HJD hr=hh:mm:ss, deg=dd:mm:ss, ang=fractional degrees ep=epoch, epj=Julian epoch, epb=Besselian epoch ts=seconds since 1950-01-01, tsu=Unix sec, tsi=IRAF sec gst=Greenwich Sidereal Time, lst=Local Sidereal Time @file: First one or two columns are in itype format ra dec sys: Need for Heliocentric conversions -a: Append date to input file, if there is one -d: Print date without time -e: Print output as ET/TDT/TT converting from UT -f: Format for output number (C printf) -h hours: Longitude in hours, west positive -l degrees: Longitude in degrees, west positive -n: Number of decimal places in sec, epoch, JD -t: Print time without date -v: Verbose getdate 3.8.4 June 2012 GETDATE(1)
All times are GMT -4. The time now is 10:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy