06-30-2011
Count occurences of a numeric string falling in a range
Dear all,
I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter.
INPUT:
1.dat
1.3
2.16
0.34
......
2.dat
1.54
0.94
3.13
.....
3.dat
2.34
4.12
2.7
.....
OUTPUT:
example-
1.dat: low (2>) - 200 ; medium (3> and 2<) - 50 ; high (3<) -250
(the output can be in any comprehensive format)
I used the following script, in vain!
Code:
#!/bin/csh
set k = 1
while ($k = 250)
set i=0
set low = 0
set medium = 0
set high = 0
foreach line ("`cat $k.dat`")
set j = `printf $line`
if ($j < 2) then
@low = $low +1
else if ($j > 2 and <3) then
@medium = $medium +1
else if ($j > 3) then
@high = $high +1
else
endif
end
echo "$k - $low $medium $high"
@k = $k +1
end
I get an error sayin "if: Badly formed number.
Could you please help?
Thanks,
Po
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
i have a string like echo "a|b|c" . i want to count the | symbols in this string . how to do this .plz tell the command (11 Replies)
Discussion started by: kamesh83
11 Replies
2. Shell Programming and Scripting
I have two files.And a sort of matrix analysis.
Both files have a string followed by two numbers:
File 1:
A 2 7
B 3 11
C 5 10
......
File 2:
X 1 10
Y 3 5
Z 5 9
What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in... (7 Replies)
Discussion started by: dcfargo
7 Replies
3. Shell Programming and Scripting
Hi all,
I have a pattern like this in a file:
123 4 56 789
234 5 67 789
121 3 56 789
222 4 65 789
321 6 90 100
478 8 40 789
243 7 80 789
How can I count the number of occurences of '789' (4th column) in this set...?
Thanks for all your help!
K (7 Replies)
Discussion started by: kripssmart
7 Replies
4. Shell Programming and Scripting
I have enclosed the script. I am able to find the files that contain my search string but when I try to count the occurences within the file I get zero always. Any help on this.
#!/usr/bin/perl
my $find = $ARGV;
my $replace = $ARGV;
my $glob = $ARGV;
@filelist = <*$glob>;
# process each... (22 Replies)
Discussion started by: TimHortons
22 Replies
5. Shell Programming and Scripting
Hi,
i am in need of an awk script to accomplish the following:
Input table looks like:
Student1 arts
Student2 science
Student3 arts
Student4 science
Student5 science
Student6 science
Student7 science
Student8 science
Student9 science
Student10 science
Student11 science... (8 Replies)
Discussion started by: saint2006
8 Replies
6. Shell Programming and Scripting
Hi,
Please help me in finding the number of occurences of the string.
Example: Apple, green, blue, Apple, Orange, green, blue are the strings can be even in the next line.
The o/p should look as:
Word Count
----- -----
Apple 2
green 2
Orange 1
blue 2
Thanks (2 Replies)
Discussion started by: acc888
2 Replies
7. UNIX for Dummies Questions & Answers
hi,
I have a text..and i need to find a pattern in the text and count to the no of times the pattern occured.
i have used grep command ..but the problem is , it shows the occurrences of the pattern but doesn't count no of times the pattern occuries. (5 Replies)
Discussion started by: nvnni
5 Replies
8. Shell Programming and Scripting
line number:status, market, keystation
1,SENT,EBS,1 : 1
2,DONE,REU,1 : 1
3,SENT,EBS,2 : 1
4,DONE,EBS,1 : 0
5,SENT,EBS,2 : 0
6,SENT,EBS,2 : 0
7,SENT,EBS,2 : 0
8,SENT,EBS,1 : 1
for each status, market combination I want to keep a tally of active orders. i.e if an order is SENT, then +1, if... (8 Replies)
Discussion started by: Calypso
8 Replies
9. Shell Programming and Scripting
Hi All,
I have a file which contains lakhs of records
0136812368126 03000 Statement
1237129372189 02321 JIT
0136812368126 05000 terminal
1237129372189 05001 Utilise
Is there an option to delete all lines which fall within the range 05000 to 05999?
I tried... (6 Replies)
Discussion started by: swasid
6 Replies
10. Shell Programming and Scripting
I have some text files in a folder f1 with 10 columns. The first five columns of a file are shown below.
aab abb 263-455 263 455
aab abb 263-455 263 455
aab abb 263-455 263 455
bbb abb 26-455 26 455
bbb abb 26-455 26 455
bbb aka 264-266 264 266
bga bga 230-232 230 ... (10 Replies)
Discussion started by: gomez
10 Replies
LEARN ABOUT CENTOS
trace-cmd-restore
TRACE-CMD-RESTORE(1) TRACE-CMD-RESTORE(1)
NAME
trace-cmd-restore - restore a failed trace record
SYNOPSIS
trace-cmd restore [OPTIONS] [command] cpu-file [cpu-file ...]
DESCRIPTION
The trace-cmd(1) restore command will restore a crashed trace-cmd-record(1) file. If for some reason a trace-cmd record fails, it will
leave a the per-cpu data files and not create the final trace.dat file. The trace-cmd restore will append the files to create a working
trace.dat file that can be read with trace-cmd-report(1).
When trace-cmd record runs, it spawns off a process per CPU and writes to a per cpu file usually called trace.dat.cpuX, where X represents
the CPU number that it is tracing. If the -o option was used in the trace-cmd record, then the CPU data files will have that name instead
of the trace.dat name. If a unexpected crash occurs before the tracing is finished, then the per CPU files will still exist but there will
not be any trace.dat file to read from. trace-cmd restore will allow you to create a trace.dat file with the existing data files.
OPTIONS
-c
Create a partial trace.dat file from the machine, to be used with a full trace-cmd restore at another time. This option is useful for
embedded devices. If a server contains the cpu files of a crashed trace-cmd record (or trace-cmd listen), trace-cmd restore can be
executed on the embedded device with the -c option to get all the stored information of that embedded device. Then the file created
could be copied to the server to run the trace-cmd restore there with the cpu files.
If *-o* is not specified, then the file created will be called
'trace-partial.dat'. This is because the file is not a full version
of something that trace-cmd-report(1) could use.
-t tracing_dir
Used with -c, it overrides the location to read the events from. By default, tracing information is read from the debugfs/tracing
directory. -t will use that location instead. This can be useful if the trace.dat file to create is from another machine. Just tar
-cvf events.tar debugfs/tracing and copy and untar that file locally, and use that directory instead.
-k kallsyms
Used with -c, it overrides where to read the kallsyms file from. By default, /proc/kallsyms is used. -k will override the file to read
the kallsyms from. This can be useful if the trace.dat file to create is from another machine. Just copy the /proc/kallsyms file
locally, and use -k to point to that file.
-o output'
By default, trace-cmd restore will create a trace.dat file (or trace-partial.dat if -c is specified). You can specify a different file
to write to with the -o option.
-i input
By default, trace-cmd restore will read the information of the current system to create the initial data stored in the trace.dat file.
If the crash was on another machine, then that machine should have the trace-cmd restore run with the -c option to create the trace.dat
partial file. Then that file can be copied to the current machine where trace-cmd restore will use -i to load that file instead of
reading from the current system.
EXAMPLES
If a crash happened on another box, you could run:
$ trace-cmd restore -c -o box-partial.dat
Then on the server that has the cpu files:
$ trace-cmd restore -i box-partial.dat trace.dat.cpu0 trace.dat.cpu1
This would create a trace.dat file for the embedded box.
SEE ALSO
trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1), trace-cmd-stop(1), trace-cmd-extract(1), trace-cmd-reset(1),
trace-cmd-split(1), trace-cmd-list(1), trace-cmd-listen(1)
AUTHOR
Written by Steven Rostedt, <rostedt@goodmis.org[1]>
RESOURCES
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
COPYING
Copyright (C) 2010 Red Hat, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL).
NOTES
1. rostedt@goodmis.org
mailto:rostedt@goodmis.org
06/11/2014 TRACE-CMD-RESTORE(1)