pvaneynd: (Default)
Today I helped a collegue who came with the question: I have two files, how do I find which lines were added to one file, but not to the other?

He was thinking of a program to write. I'm more a KISS person, why waste time writing a program when brute force will do just fine.

So:

We have two files a and b:

pevaneyn@mac-book:/tmp :) $ cat a
1
2
3
4
5
pevaneyn@mac-book:/tmp :) $ cat b
1
2
3
4
5
7
8


We want to see the lines in b which are not in a:

pevaneyn@mac-book:/tmp :) $ cat a b | sort | uniq -u
7
8


So we take the two files, sort then and then print the unique lines.

But what if there are also unique lines in a which we don't need? So let's add a line to 0 which we do not want to see in the output:

pevaneyn@mac-book:/tmp :) $ cat >> a
0
pevaneyn@Pmac-book:/tmp :) $ cat a b | sort | uniq -u
0
7
8


How do we remove this 0?

A trick is to include a twice, then a line in a will never be unique:

pevaneyn@mac-book:/tmp :) $ cat a a b | sort | uniq -u
7
8


I used a similar method today to find which interface gave the CRC errors...
pvaneynd: (Default)
For a side project at $WORK I need to plot some data.

In the past I used gnuplot but as I wanted to interactively investigate the data I wrote a GUI browser in Clojure. This was relatively easy and fast enough.

But I've been told that I'm not with the new hotness and that I should investigate doing this in the browser. So I found the pretty impressive dygraphs javascript library.

The plots look fantastic and are really what I need. So I make my first html5 like page and tried it.

At first I thought that something was wrong. If I do this plot with gnuplot I get:

$ time gnuplot plot.gnuplot

real	0m0.818s
user	0m0.608s
sys	0m0.209s


In Safari it took 22 minutes, while showing a beachball all the time, to plot this data. Chrome and Firefox do it quite a bit better at only two minutes, but still... not subsecond is it? Using the 'canvas' html5 terminal in gnuplot produces 14M html file which only takes something lik 20 seconds to get drawn in all browsers.

But I must admit that the default look and interactivity of dygraph is lightyears ahead of my gnuplot settings...

Profile

pvaneynd: (Default)
pvaneynd

March 2017

S M T W T F S
   1234
567891011
12131415 161718
19202122232425
26272829 3031 

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 22nd, 2017 02:45 am
Powered by Dreamwidth Studios