Your code prints the lines for 10pm on Sunday, October 15, 2017 (from the 2nd statement in the first line of your awk code. I assume that the value you seem to want from those lines total up to zero. But the calculations in your script (from the statement on lines 2 through 10 in your awk script) are performed on every line in the file; not just those that you print (since the condition on that statement is the empty expression).
Again, you say the output is not what you want, but do not clearly show us what output you are trying to produce.
And, you have not shown us the input that you are feeding this script. So, we have no idea where the 5 is coming from either. If your input file contained the line:
plus the first three lines shown in your output and $pattern expands to an empty string, you would likely get the output you showed us.
maybe if i word this differently, it'll be clearer.
the data file that the awk code is scanning as many lines similar to this (and they all have different time stamps on them):
the lines i care about, in this particular scenario are all lines that have the 10PM timestamp on them.
ok, so when the awk code finds those lines that contain 10PM on them, it should do what my original request in the original post of this thread was about....which is to add up all the numbers in the 9th field, provided a specific pattern was not specified.
if a specific pattern to search for in field 9 was not provided, then the "$pattern" variable would be empty. And yes, in this case, it is empty. i did not specify a pattern.
Hello..
I have got one file ...
I want to add line numbers with space form starting to ending..
for example...if the file is
--------------------------
sand sorcd 2345 345
recds 234 234 5687
yeres 568 988 erfg4 67
--------------------------
I need the output
... (4 Replies)
Hi i would like to add line numbers to end of each line in a file.
I am able to do it in the front of each line using sed, but not able to add at the end of the file.
Can anyone suggest
The following code adds line number to start of each line
sed = filename | sed 'N;s/\n/\t/'
how can i... (5 Replies)
Hi,
I want to add two fields with values '1000' and 'XYZ-1234' at the end of every line in a comma delimited file.
Should I use any command in a loop to add the fields or using any single command Shall I acheive it?
Kindly help me in code.
Thanks,
Poova. (6 Replies)
I have a bash script which takes a log file with each record separated by a #. The records have multiple fields but field $1 is always the date and time. When the script is run it prints the record just fine from oldest to newest. I need to have records print out from newest first.
Here is the... (7 Replies)
echo "0.1 2.0 0.4 2.0 4.3 1.0 6.0 9.0" | awk 'BEGIN {total=0} {total += $1} END {print total}'
I want to add the above output from the echo command, but i can't figure this out. The output above always spits out inaccurate numbers.
can someone please provide me with a one liner similar to... (4 Replies)
Hey all,
Unfortunately I have only basic knowledge of awk and/or scripting. If I have a file with lines that can look similar to this:
Name=line1 Arg1=valueA Arg2=valueB Arg3=valueC
Name=line2 Arg1=valueD
Name=line3 Arg1=valueE Arg3=valueF
Name=line4 Arg2=valueG ... (4 Replies)
Hi,
I need to number the lines in my text file. I know how to do this with standard numbering (1,2,3,4, etc) but I need to count in multiples of 5, beginning 0,5,10,15...
example existing file:
abcd
efg
hijklm
nopqrs
desired output
0 abcd
5 efg
10 hijklm
15 ... (11 Replies)
Hi,
i have a file, where measurement-data is stored in the first column. The file has also a header of 5 lines. I want to set counting up numbers in front of any particular measurement-value; should start at the 6. line with starting number 1.
i try to solve it with ...
awk 'NR > 6 { print... (6 Replies)
I am trying to use awk to identify and print out records in fields that are empty along with which line they are in. I hope the awk below is close, it runs but nothing results. Thank you :).
awk
awk -F'\t' 'FNR==NR ~ /^*$/ { print "NR is empty" }' file
file
123 GOOD ID 45... (3 Replies)