For years I've noticed GNU's grep in Unixes (not just Linux flavors) detected that I was using a color-capable TERM interactively like xterm/gnome-terminal/kconsole, and nicely colored my search expressions among the context.
What might be a simple cli tool that only boldens/highlights your regex or simple search string, but unlike grep, doesn't otherwise filter out any lines? Maybe a sed trick can do this, which I can alias and later pipe commands to?
EXAMPLE
So I wrote a program pricehist.sh which normally produces CSV-like data for another program, but I frequently visually inspect it like so:
./pricehist.sh mostalexp-GPW 28 |sort -r -g -k 3 -t ' ' |column -t -s", "
MOSTALEXP,20120222,0.78,0.79,0.76,0.77,63900,0.77 0.04000 5.00000 -0.01000 -1.25000 49203
MOSTALEXP,20120203,0.82,0.82,0.78,0.78,446089,0.78 0.04000 4.87805 0 0 347949
MOSTALEXP,20120124,0.71,0.71,0.69,0.71,61478,0.71 0.03000 4.16667 -0.01000 -1.38889 43649
MOSTALEXP,20120130,0.73,0.73,0.70,0.73,59488,0.73 0.03000 4.10959 0 0 43426
MOSTALEXP,20120210,0.79,0.81,0.77,0.81,104120,0.81 0.03000 3.75000 0.01000 1.25000 84337
MOSTALEXP,20120213,0.80,0.80,0.78,0.80,86606,0.80 0.03000 3.70370 -0.01000 -1.23457 69284
MOSTALEXP,20120126,0.69,0.75,0.69,0.72,146353,0.72 0.02000 2.81690 0.04000 5.63380 105374
MOSTALEXP,20120131,0.72,0.73,0.71,0.72,72734,0.72 0.02000 2.73973 0 0 52368
MOSTALEXP,20120123,0.72,0.73,0.71,0.72,24133,0.72 0.02000 2.73973 0 0 17375
MOSTALEXP,20120214,0.78,0.81,0.78,0.79,56990,0.79 0.02000 2.50000 0.01000 1.25000 45022
MOSTALEXP,20120209,0.79,0.82,0.79,0.80,65243,0.80 0.02000 2.46914 0.01000 1.23457 52194
MOSTALEXP,20120118,0.69,0.70,0.68,0.69,62520,0.69 0.01000 1.44928 0.01000 1.44928 43138
MOSTALEXP,20120125,0.70,0.71,0.70,0.71,92317,0.71 0.01000 1.40845 0 0 65545
MOSTALEXP,20120201,0.71,0.74,0.71,0.74,199791,0.74 0.01000 1.38889 0.02000 2.77778 147845
MOSTALEXP,20120127,0.73,0.73,0.71,0.73,38157,0.73 0.01000 1.38889 0.01000 1.38889 27854
MOSTALEXP,20120207,0.78,0.79,0.77,0.79,56243,0.79 0.01000 1.28205 0.01000 1.28205 44431
MOSTALEXP,20120206,0.78,0.80,0.77,0.78,133597,0.78 0.01000 1.28205 0.02000 2.56410 104205
MOSTALEXP,20120221,0.81,0.81,0.79,0.80,112738,0.80 0.01000 1.25000 0.01000 1.25000 90190
MOSTALEXP,20120217,0.80,0.85,0.79,0.80,272245,0.80 0.01000 1.25000 0.05000 6.25000 217796
MOSTALEXP,20120216,0.81,0.81,0.79,0.80,30814,0.80 0.01000 1.25000 0.01000 1.25000 24651
MOSTALEXP,20120113,0.66,0.66,0.65,0.65,90267,0.65 0.00500 0.76336 0.00500 0.76336 58673
MOSTALEXP,20120220,0.80,0.82,0.80,0.80,83881,0.80 0 0 0.02000 2.50000 67104
MOSTALEXP,20120215,0.80,0.82,0.79,0.80,128714,0.80 0 0 0.03000 3.79747 102971
MOSTALEXP,20120208,0.79,0.84,0.79,0.81,280446,0.81 0 0 0.05000 6.32911 227161
MOSTALEXP,20120120,0.74,0.74,0.72,0.73,128831,0.73 0 0 0.02000 2.77778 94046
MOSTALEXP,20120117,0.67,0.71,0.67,0.69,284886,0.69 0 0 0.04000 5.97015 196571
MOSTALEXP,20120116,0.65,0.67,0.65,0.67,9548,0.67 0 0 0.02000 3.07692 6397
MOSTALEXP,20120202,0.75,0.87,0.75,0.82,1270955,0.82 -0.01000 -1.35135 0.13000 17.56757 1042183
MOSTALEXP,20120119,0.70,0.74,0.70,0.72,320471,0.72 -0.01000 -1.44928 0.05000 7.24638 230739
At the end of the pipe (after |column -t
) it'd be nice to add something which highlights at least the string $(date +%Y%m%d)
, which at the moment evaluates to 20120222
Another example is tail -F /tmp/*.log | grep -C 9999 YouJustGotHacked
except I wouldn't want the grep to actually filter out any lines, just make YouJustGotHacked a lot easier to spot in the noise.
Source: (StackOverflow)
I would like to find a way to build a Kiama like library with an added feature that would be to have strongly typed rewrite rules. (In Kiama eveyrything is a Term, and rewrite rules are Term => Option[Term]
I know that shapeless allows to convert arbitrary case class hierarchies to a sum of products representation using hlists behind the scenes.
Based on this generic representation I imagine it could be fairly doable to write a generic library of traversal combinators (in the style of stratego) for applying rewrite rules on the generic version of a term made of nested case classe,
I have the feeling that it could be possible to use shapeless polyN functions to encode polymorphic term rewrite rules that would yield precise types, however these rewrite rules would have to operate on Hlists representing the case classes, which could be quite cumbersome to use compared to how pattern matching allows to match and transform sub trees
The simple example I have is this one
sealed abstract trait Expr { type Repr }
sealed abstract trait BoolExpr extends Expr { type Repr = Boolean }
sealed abstract trait IntExpr extends Expr { type Repr = Int }
case class BoolVar(sym: Symbol) extends BoolExpr
case class Not( l: BoolExpr ) extends BoolExpr
case class And( l: BoolExpr, r: IntExpr ) extends BoolExpr
case class Or( l: BoolExpr, r: IntExpr ) extends BoolExpr
case class IntIte( cond: BoolExpr, thenExpr: IntExpr, elseExpr: IntExpr) extends IntExpr
case class IntConst( value: Int ) extends IntExpr
case class IntVar( sym: Symbol ) extends IntExpr
rule1 { case Not(Not(e)) => Some(e) }
rule2 { case IntIte(Not(c), t, e) => Some( IntIte(c, e, t) }
however, I fear that the rewrite rules would have to be expressed over hlists and hence I would loose the power of simple pattern matching as illustrated above. The only thing I can imagine is to, while traversing the shapeless.Generic structure, convert back bits of it before matching a rule and convert back the result to generic and update the generic structure with the new term represented as a hlist.
Even better would be a rewriting system working on a GADT Expr[T] where T is the type of the expressions and rewrite rules would preserve that T.
Regards.
How feasible does this look to you?
Source: (StackOverflow)