Fairly easy in Tcl. I'm not sure how you'd go about doing it in a "standard" shell script like Ksh, Bash, etc.
Tcl is pretty good for this because all variables are both strings and "lists" (sorta like arrays).
Code:
#! /usr/bin/tclsh
# open the data file for reading.
set fid [open /path/to/matrix.data r]
# loop through all lines in the file.
while { ![eof $fid] } {
gets $fid row
# Row are: ID, X1, X2, Y1, Y2
# We don't care if the ID row is higer than
# .5, so don't check it.
set data [lrange $row 1 end]
#data = X!, X2, Y1, Y2.
# so foreach d $data will check the individual elements of the list.
foreach d $data {
if { $d >= 0.5 } {
set newdata $row
}
}
# if we have a match from above, then
# spit out the entire row.
if { $newdata != "" } {
puts stdout $newdata
set newdata ""
}
}
# close the file.
close $fid
Hi,
I have a file whose structure is like this
7
7
1 2 3 4 5
1 3 4 8 6
1 4 5 6 0
2 6 8 3 8
2 5 7 8 0
5 7 9 4 1
3 8 0 2 2
3 5 6 8
basically first two row tell the number of rows and column but the data following them are not arranged in that format. now i want to create another... (1 Reply)
Hi,
I have a list of 70 files in a directory and I need to merge the content of each file into one big matrix file (71 columns x 3060 rows).
Each file has the following format only two columns per file:
unique identifier1
randomtext1 randomtext1
a 5
b 3
c 6
d 3
e 2... (11 Replies)
My input:
Data name: ABC001
Data length: 1000
Detail info
Data Direction Start_time End_time Length
1 forward 10 100 90
1 forward 15 200 185
2 reverse 50 500 450
Data name: XFG110
Data length: 100
Detail info
Data Direction Start_time End_time Length
1 forward 50 100 50 ... (11 Replies)
I have columnar data in arrays perl, Example -
@a = (1,2,3);
@array1 = (A,B,C);
@array2 = (D,E,F);
@array3 = (I,R,T);
I want the data to be formatted and printed as
1 A D I
2 B E F
3 C F T
and so on... (8 Replies)
I have a huge file (about 2 millions records) contains data separated by “,” (comma). As part of the requirement, I can't change the format. The objective is to remove some of the records with the following condition. If the 23rd field on each line start with 302 , I need to remove that from the... (4 Replies)
Hi all,
Is there a way to convert full data matrix to linearised left data matrix?
e.g full data matrix
Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7
Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245
Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Hi,
Some assistance with respect to the following problem will be very helpful.
I want to reformat my dataset in the following manner for subsequent analysis.
I have first column values (which repeat for each value of 2nd column) which are names, the second column specifies position ad the... (1 Reply)
I have a file that contains 2 columns tag,pos
cat input_file
tag pos
atg 10
ata 16
agt 15
agg 19
atg 17
agg 14
I have used following command to sort the file based on second column
sort -k 2 input_file
tag pos
atg 10
agg 14
agt 15
ata 16
agg 19
atg 17 (2 Replies)
Hi There,
I want to convert the following data into tabular matrix, based on column 4th and 5th, and output the column 10th value
chr1 2804449 2804450 NACpG_1 window1 + chr1 2804443 2804475 1
chr1 2804450 2804451 NACpG_1 window2 + chr1 2804443 ... (3 Replies)
Discussion started by: ChiragNepal
3 Replies
LEARN ABOUT MOJAVE
configbody
configbody(n) [incr Tcl] configbody(n)
__________________________________________________________________________________________________________________________________________________NAME
configbody - change the "config" code for a public variable
SYNOPSIS
itcl::configbody className::varName body
_________________________________________________________________DESCRIPTION
The configbody command is used outside of an [incr Tcl] class definition to define or redefine the configuration code associated with a
public variable. Public variables act like configuration options for an object. They can be modified outside the class scope using the
built-in configure method. Each variable can have a bit of "config" code associate with it that is automatically executed when the vari-
able is configured. The configbody command can be used to define or redefine this body of code.
Like the body command, this facility allows a class definition to have separate "interface" and "implementation" parts. The "interface"
part is a class command with declarations for methods, procs, instance variables and common variables. The "implementation" part is a
series of body and configbody commands. If the "implementation" part is kept in a separate file, it can be sourced again and again as bugs
are fixed, to support interactive development. When using the "tcl" mode in the emacs editor, the "interface" and "implementation" parts
can be kept in the same file; as bugs are fixed, individual bodies can be highlighted and sent to the test application.
The name "className::varName" identifies the public variable being updated. If the body string starts with "@", it is treated as the sym-
bolic name for a C procedure. Otherwise, it is treated as a Tcl command script.
Symbolic names for C procedures are established by registering procedures via Itcl_RegisterC(). This is usually done in the Tcl_AppInit()
procedure, which is automatically called when the interpreter starts up. In the following example, the procedure My_FooCmd() is registered
with the symbolic name "foo". This procedure can be referenced in the configbody command as "@foo".
int
Tcl_AppInit(interp)
Tcl_Interp *interp; /* Interpreter for application. */
{
if (Itcl_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
if (Itcl_RegisterC(interp, "foo", My_FooCmd) != TCL_OK) {
return TCL_ERROR;
}
}
EXAMPLE
In the following example, a "File" class is defined to represent open files. Whenever the "-name" option is configured, the existing file
is closed, and a new file is opened. Note that the "config" code for a public variable is optional. The "-access" option, for example,
does not have it.
itcl::class File {
private variable fid ""
public variable name ""
public variable access "r"
constructor {args} {
eval configure $args
}
destructor {
if {$fid != ""} {
close $fid
}
}
method get {}
method put {line}
method eof {}
}
itcl::body File::get {} {
return [gets $fid]
}
itcl::body File::put {line} {
puts $fid $line
}
itcl::body File::eof {} {
return [::eof $fid]
}
itcl::configbody File::name {
if {$fid != ""} {
close $fid
}
set fid [open $name $access]
}
#
# See the File class in action:
#
File x
x configure -name /etc/passwd
while {![x eof]} {
puts "=> [x get]"
}
itcl::delete object x
KEYWORDS
class, object, variable, configure
itcl 3.0 configbody(n)