Script to parse a large text file, from rows to columns - parsing

I want a parsing script/ code solution in any programing language.
The file is too large to be open in Excel.
Problem:
I have large text file (300MB) which look like this:
[0] 2014 Jul 23 08:15:16.675
Current SFN = 604
Current Subframe Number = 3
Is Restricted = false
Cell Timing[0] = 298955
[1] 2014 Jul 24 08:15:16.675
Current SFN = 605
Current Subframe Number = 4
Is Restricted = false
Cell Timing[0] = 298900
[2] 2014 Jul 25 08:15:16.675
Current SFN = 700
Current Subframe Number = 7
Is Restricted = false
Cell Timing[0] = 39025
Wanted output:
5 columns ( Date , Current SFN , Current Subframe Number , Is Restricted , Cell Timing[0] )
Date Current SFN Current Subframe Number Is Restricted Cell Timing[0]
2014 Jul 23 08:15:16.675 604 3 TRUE 298955
2014 Jul 24 08:15:16.675 605 4 FALSE 298900
2014 Jul 25 08:15:16.675 700 7 FALSE 39025

Related

Swift iOS DateFormatter for Japanase Calendar

I'm extracting a date from a zip file, if the calendar is Japanese, it extract this string:
[R 2/03/13 19:00:17]
that is 13-mar-2020 19:00:17
I found on iOS documentation that dateFormatter.locale = Locale(identifier: "ja_JP")is printing:
// Japanese Locale (ja_JP)
dateFormatter.locale = Locale(identifier: "ja_JP")
print(dateFormatter.string(from: date)) // 2001/01/02
By searching on internet, I think the "R" is meaning Reiwa Era.
Do exist a dateFormat that could give the year?
Something like:
let stringJap = "[R 2/03/13 19:00:17]"
let stringJapDate = stringJap.replacingOccurrences(of: "[", with: "").replacingOccurrences(of: "]", with: "")
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "ja_JP")
dateFormatter.dateFormat = "? y-MM-dd HH:mm:ss" // the "?" means if is existing a character to describe Era in Japanase
let date = dateFormatter.date(from:stringJapDate)!
I'd avoid to build a switch case to extract the year by following the table below.
I found on internet this Era conversion:
2019 - Present ~ Reiwa Era
Western Calendar Japanese Calendar Western Calendar Japanese Calendar
2020 Reiwa 2 2019 Reiwa 1 / Heisei 31
1989 - 2019 ~ Heisei Era
Western Calendar Japanese Calendar Western Calendar Japanese Calendar
2019 Reiwa 1 / Heisei 31
2018 Heisei 30 2003 Heisei 15
2017 Heisei 29 2002 Heisei 14
2016 Heisei 28 2001 Heisei 13
2015 Heisei 27 2000 Heisei 12
2014 Heisei 26 1999 Heisei 11
2013 Heisei 25 1998 Heisei 10
2012 Heisei 24 1997 Heisei 9
2011 Heisei 23 1996 Heisei 8
2010 Heisei 22 1995 Heisei 7
2009 Heisei 21 1994 Heisei 6
2008 Heisei 20 1993 Heisei 5
2007 Heisei 19 1992 Heisei 4
2006 Heisei 18 1991 Heisei 3
2005 Heisei 17 1990 Heisei 2
2004 Heisei 16 1989 Heisei 1 / Showa 64
Any help?
Thanks

How to get the difference of weekdays?

I have this information:
Days Dec'15 Jan'16
---------------------
Sun 27
Mon 28
Tue 29
Wed 30
Thu 31
Fri 1
Sat 2
I have 1st Jan'16. So I have to get Fri and then the difference of days from the Sun. So, in this case, the difference should be 5. Because, before Friday there are 5 other days. So if I want to know it for 2nd Jan'16 it should be 6. And likewise.
How do I get it easy with date functions?
The following code may help you
extension Date {
func weekdayDiffence() -> Int {
return Calendar.current.dateComponents([Calendar.Component.weekday], from: self).weekday ?? 0
}
}
Example
let d = Date().weekdayDiffence()
print(d)

Json result format in mvc

I want to read the text file into json. i have a text file with three lines.
While i tried to read using json .It returns all the 3 lines into one string.
Here is my code for your reference :
[System.Web.Mvc.HttpPost]
public JsonResult upload(HttpPostedFileBase file)
{
bool result = false;
StringBuilder strbuild = new StringBuilder();
try
{
if (file.ContentLength == 0)
throw new Exception("Zero length file!");
else
{
var fileName = Path.GetFileName(file.FileName);
var filePath = Path.Combine(Server.MapPath("~/Downloads"), fileName);
file.SaveAs(filePath);
if (!string.IsNullOrEmpty(filePath))
{
using (StreamReader sr = new StreamReader(Path.Combine(Server.MapPath("~/Downloads"), fileName)))
{
while (sr.Peek() >= 0)
{
strbuild.AppendFormat(sr.ReadLine());
}
}
}
}
}
catch (Exception)
{
result = false;
}
return new JsonResult()
{
Data = strbuild.ToString()
};
}
My Result is :
"HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- 15 JUL 201615 JUL 2016 HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816AREBECCA SIOW SIQIN S1234567E 04 FEB 1995C O F- 15 JUL 201615 JUL 2016 HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ASAMANTHA SIOW SIHUI S1234567J 18 NOV 1993C O F- 15 JUL 201615 JUL 2016 "
My Text File is :
line 1:
HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- 15 JUL 201615 JUL 2016
line 2 :
HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816AREBECCA SIOW SIQIN S1234567E 04 FEB 1995C O F- 15 JUL 201615 JUL 2016
Line 3:
HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H-000001 15 JUL 201614 JUL 20170816ASAMANTHA SIOW SIHUI S1234567J 18 NOV 1993C O F- 15 JUL 201615 JUL 2016
So how can i show the json result with 3 (String) lines ?
Thanks in advance !!!

DataTables in mvc

I have a string, named s respectively. The string s looks like :
"HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F-
HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F-
HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
I split the string based on rows. The code is
string s = sr.ReadToEnd();
string[] Mem = s.Split('\r');
So, Now the string[] Mem looks like :
"HD-M-16-H-000001*1001*1 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
"HD-M-16-H-000001*1001*2 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
"HD-M-16-H-000001*1001*3 HD-M-16-H-000001*1001 HD-M-16-H 000001 15 JUL 201614 JUL 20170816ACHEONG SIEW FUNG 12345678I 22 DEC 1960SPO F- "
Now, actually i am looking to create a dataTable with 'n' number of columns to hold Each word of each string in Mem.
The below code that takes each line of string[] and holds it into string. Then i split the string
string firststr = Mem.First();
string secondstr = Mem[1];
string thirdstr = Mem[2];
string str = firststr.Substring(0, 30);
string[] m = str.Split('\r');
Actually i want to store all the three string[] to one string datatype with 3 strings and split each line of string by substr using loop(foreach or While). So how can i acheive this???
Any help appreciated. Thanks in advance !!!!

Is my gradient checking method correct and my gradient calculation wrong, or vice versa?

My network only achieve around 80%, but the reported best score is around 85% accuracy. I m using same input data and same initalization. I dont know whats wrong, so I try to check my gradients and implemented what is recommended for gradient checking: http://ufldl.stanford.edu/tutorial/supervised/DebuggingGradientChecking/
But i m not sure, if my implementation is correct:
public void gradientchecking(double[] theta){
System.out.println("Gradient Checking started");
//costfunction returns cost and gradients
IPair<Double, double[]> org = costfunction(theta);
double[] theta_pos = new double[theta.length];
double[] theta_neg = new double[theta.length];
for (int i = 0; i < theta.length; i++) {
theta_pos[i]= theta[i];
theta_neg[i]=theta[i];
}
double mu = 1e-5;
for (int k = 0; k < 20; k++) {
theta_pos[k] = theta_pos[k] + mu;
theta_neg[k] = theta_neg[k] - mu;
IPair<Double, double[]> pos = costfunction(theta_pos);
IPair<Double, double[]> neg = costfunction(theta_neg);
System.out.println("Org: "+org.getSecond()[k] +" check:"+ ((pos.getSecond()[k]-neg.getSecond()[k])/(2*mu)));
//System.out.println("Org: "+org.getSecond()[k] +"check:"+ ((pos.getSecond()[k]-neg.getSecond()[k])/(2*mu)));
theta_pos[k] = theta_pos[k] - mu;
theta_neg[k] = theta_neg[k] + mu;
}
}
}
I got the following result after a freshly initialized theta:
Gradient Checking started
Cost: 1.1287071297725055 | Wrong: 124 | start: Thu Jul 30 22:57:08 CEST 2015 |end: Thu Jul 30 22:57:18 CEST 2015
Cost: 1.128707130295382 | Wrong: 124 | start: Thu Jul 30 22:57:18 CEST 2015 |end: Thu Jul 30 22:57:28 CEST 2015
Cost: 1.1287071292496391 | Wrong: 124 | start: Thu Jul 30 22:57:28 CEST 2015 |end: Thu Jul 30 22:57:38 CEST 2015
Org: 5.2287135944026004E-5 check:1.0184607936733826E-4
Cost: 1.1287071299252593 | Wrong: 124 | start: Thu Jul 30 22:57:38 CEST 2015 |end: Thu Jul 30 22:57:47 CEST 2015
Cost: 1.1287071296197628 | Wrong: 124 | start: Thu Jul 30 22:57:47 CEST 2015 |end: Thu Jul 30 22:57:56 CEST 2015
Org: 1.5274823511207024E-5 check:1.141254586229615E-4
Cost: 1.1287071299063134 | Wrong: 124 | start: Thu Jul 30 22:57:56 CEST 2015 |end: Thu Jul 30 22:58:05 CEST 2015
Cost: 1.1287071296387077 | Wrong: 124 | start: Thu Jul 30 22:58:05 CEST 2015 |end: Thu Jul 30 22:58:14 CEST 2015
Org: 1.3380293717695182E-5 check:1.0008639478696018E-4
Cost: 1.1287071297943114 | Wrong: 124 | start: Thu Jul 30 22:58:14 CEST 2015 |end: Thu Jul 30 22:58:23 CEST 2015
Cost: 1.1287071297507094 | Wrong: 124 | start: Thu Jul 30 22:58:23 CEST 2015 |end: Thu Jul 30 22:58:32 CEST 2015
Org: 2.1800899147740388E-6 check:9.980780136716263E-5
that indicates that my gradient calculation has an error, or the gradientchecking() method. I m not sure, can somebody help me?
In Java arrays are reference types.
int[] arr = { 8,7,6,5,4,3,2,1,8};
int[] b = arr;
b [0] = -10;
for (int i:arr) {
System.out.print (' ');
System.out.print (i);
}
outputs -10 7 6 5 4 3 2 1 8
So i mean that you incorrectly creating arrays
double[] theta_pos = theta;
double[] theta_neg = theta;
they are just references to theta, and by changing their contents you change theta also, +mu-mu = 0. Use clone() methods while copying array.
double[] theta_pos = theta.clone();
double[] theta_neg = theta.clone();
But remember that clone may not work as you expecting in some cases, with simple(non-reference) types it works ideal. Look at this
Does calling clone() on an array also clone its contents?

Resources