Questions tagged [expr]

Command-line expression evaluator

The expr utility evaluates expressions and writes the result on standard output.

See the FreeBSD Man page.

102 questions
14
votes
3 answers

Multiplication with expr in shell script

I am making a basic calculator to add, subtract, multiply, and divide. Addition works, but not multiplication. When I attempt to multiply, I get the "You did not run the program correctly" response: $ ./calculator 4 + 5 9 $ ./calculator 4 * 5 You…
Alex Wolfe
  • 141
  • 1
  • 1
  • 3
10
votes
2 answers

MongoDB find expr with multiple eq

This query which should filter results by the month seems to be working fine. But I can't figure out how to add a year filter as well. db.collection.find({ "$expr": { "$eq": [{ "$month": "$timestamp" }, 12] } }); I tried to come up with…
user4123355
6
votes
2 answers

Replace parentheses in pyspark with replace_regex

+---+------------+ | A| B| +---+------------+ | x1| [s1]| | x2| [s2 (A2)]| | x3| [s3 (A3)]| | x4| [s4 (A4)]| | x5| [s5 (A5)]| | x6| [s6 (A6)]| +---+------------+ The desired result: +---+------------+-------+ |A |B …
Sadek
  • 127
  • 1
  • 8
4
votes
4 answers

select column names containing string programmatically

Given a data frame like: df <- data.frame(z_a = 1:2, z_b = 1:2, y_a = 3:4, y_b = 3:4) I can select columns names that contain a character with: library(dplyr) df %>% select(contains("a"),…
CPak
  • 13,260
  • 3
  • 30
  • 48
3
votes
3 answers

Why does Tcl expr consider some number as "empty" while it's really not empty?

Problem Statement I'm importing a set of coordinate from an unknown source, which I don't have privilege to look into. set yMin [lindex [lindex $bbox 0] 1] puts "yMin: <$yMin>" It works normally. yMin: <-6.149999999999999e-02> The brackets are…
Zureas
  • 53
  • 5
3
votes
2 answers

Why does expr fail when matching a single 0

The following command works: $ expr 1 : '\(.\)' || echo fail 1 When trying to match the string "0" the command fails, e.g. $? == 1: $ expr 0 : '\(.\)' || echo fail fail The man page says: Exit status is 0 if EXPRESSION is neither null nor 0 But,…
3
votes
2 answers

Use $regex inside $expr in mongodb aggregation

My doc looks as follows doc = { name: 'abc', age:20 } and my query looks like { $expr: {$and:[{ $gt:[ "$age", 10 ] }, { $regex:["$name",'ab']} ] } } } But it's not working and I get an…
ganesh
  • 2,024
  • 16
  • 17
3
votes
2 answers

How to use expr inside if statement?

I have not managed to understand how to embed expr in other constructs. I can easily type set i {1 2 3} expr {[llength $i]} #result is 3 However after long research I have not managed to find a way to put that inside if if {"magic tcl code with…
Draif Kroneg
  • 743
  • 13
  • 34
3
votes
2 answers

Equavalent operation of mathematica in python

Suppose that: h=[1,2,3] There is operation N[expr] in Mathematica that gives us: N[h[0]]=1, N[h[1]]=2, N[h[2]]=3 and for example N[h[6]]=0, is something like this in Python?
BASU
  • 49
  • 1
  • 3
3
votes
2 answers

What is the difference between $(()) and expr?

What is the main difference between $(()) and expr in Unix-Like systems?
SuckLips
  • 55
  • 1
  • 11
3
votes
1 answer

calling a function using expr during an LLDB session

I'm trying to get a better grasp of LLDB and am currently stuck trying to call a locally defined function (using LLDB's expr) while debugging some code. For the sake of simplicity, lets consider this toy code: testing_lldb.c: unsigned long…
banach-space
  • 1,781
  • 1
  • 12
  • 27
3
votes
2 answers

Lazy regex operator doesn't work in bash

echo "$(expr "title: Purple Haze artist: Jimi Hendrix" : 'title:\s*\(.*\?\)\s*artist.*' )" prints Purple Haze With the trailing whitespace, even though I am using the ? lazy operator. I've tested this on https://regex101.com/…
texasflood
  • 1,571
  • 1
  • 13
  • 22
3
votes
2 answers

Syntax error expr

Why does the following returning a syntax error: stringZ=abcABC123ABCabc echo `expr match "$stringZ" 'abc[A-Z]*.2'` This works on my ubuntu machine but when I try it on my mac running OS X 10.9.4 I get expr: syntax error?
rudolph9
  • 8,021
  • 9
  • 50
  • 80
2
votes
1 answer

Partially evaluate an expression in R

Sorry. I have an expression: #x^p I want to evaluate this for a given p. p -> 0 # 1 p -> 1 #x p -> 2 #x^2 p -> 3 #x^3 p -> -1 #x^-1 If I type in: p -> 1 eval(p) #1 BUT p -> 1 eval(x^p) Gives the error: #Error in eval(x^p) : object 'x' not…
heh
  • 23
  • 4
2
votes
1 answer

How to parse a formula in Pyspark?

i am new in Pyspark and I have some doubts. I have a df like this: +---+---+-------+ | a1| a2|formula| +---+---+-------+ | 18| 12| a1+a2| | 11| 1| a1-a2| +---+---+-------+ I'm trying to parse the column 'formula' to create a new column with the…
DaniloP
  • 29
  • 1
1
2 3 4 5 6 7