Skip to content

Instantly share code, notes, and snippets.

@bkamapantula
bkamapantula / readfile.py
Created October 21, 2011 19:43
Read file in Python
from numpy import*
col1_array = []
col2_array = []
col1_array_index = 1
col2_array_index = 1
for row in file("2columns.txt"):
row = row.split()
col1 = row[0]
@bkamapantula
bkamapantula / 2columns.tcl
Created October 23, 2011 03:00
Reading file with two columns in TCL - Day 2
# First three commands reads the data in to a file variable
set fp [open "2columns.txt" r]
set content [read $fp]
close $fp
# Next two commands reads all rows
set records [split $content "\n"]
set count 0
# Next commands parses each row where two columns are separated by a white-space
@bkamapantula
bkamapantula / readfile.c
Created October 24, 2011 00:49
Reading files in C - Day 3
#include <stdio.h>
//Stores line
char row[4];
void main()
{
// File variable to open file
FILE *file_pointer = fopen("2columns.txt", "r");
@bkamapantula
bkamapantula / readfile.pl
Created October 25, 2011 01:34
Reading files with two columns in Perl - Day 4
#Accepts text file with two columns and prints each column
open(input_file, "2columns.txt");
while(<input_file>)
{
# You will need it if there is whitespace at the end of line
#chomp;
#Splits the line by White-Space
@bkamapantula
bkamapantula / 2columns.txt
Created October 25, 2011 01:44
Text file with two columns
1 3
4 5
9 2
6 7
@bkamapantula
bkamapantula / readfile.rb
Created October 26, 2011 02:47
Reading files with two columns in Ruby - Day 5
# read file with two columns in Ruby
input_file = File.new("2columns.txt", "r")
while(line = input_file.gets)
col1, col2 = line.split(' ')
puts col1
puts col2
end
@bkamapantula
bkamapantula / readfile.php
Created October 27, 2011 03:29
Reading files line by line in PHP - Day 6
<?php
$input_file = fopen("2columns.txt", "r");
while(true)
{
$row = fgets($input_file);
if($row == null)
break;
echo $input_file;
}
@bkamapantula
bkamapantula / readfile.awk
Created October 29, 2011 02:16
Reading text files line by line in AWK - Day 8
BEGIN{
# Defining variables
arr_index = 0;
arr_max = 4;
}
{
# Stores first and second columns respectively for each row
col1[arr_index] = $1;
col2[arr_index] = $2;
@bkamapantula
bkamapantula / appendlines.py
Created October 31, 2011 02:29
Append text in existing file in Python - Day 11
from numpy import*
values = []
#after operations using values array, we write the output to a text file
with open("appendLines.txt", "a") as newf:
newf.write('\n')
newf.write(str(len(values)))
newf.write('\t')
@bkamapantula
bkamapantula / delete_FFL_motifs.py
Created December 1, 2011 03:28
Delete line with three columns by ID
from numpy import*
import networkx as nx
line_count = 0
G = nx.Graph()
f = open("deleted_motif_edges.txt", "w")
for row in file('100ecoliadjusted.txt'):
row.split()