Using bash -c: newvar="$(bash -c "echo $var")" Using eval: newvar="$(eval "echo $var")" Example: #!/bin/bash var='$PATH' echo "$var" #This will show that $var contains the string $PATH literally #Using bash -c newvar="$(bash -c "echo "$var"")" echo "$newvar" #using eval newvar="$(eval "echo "$var"")" echo "$newvar" It will print the environment variable paths...
I would simply start the tail in background and the python process in foreground. When the python process finishes you can kill the tail, like this: #!/bin/bash touch /tmp/out # Make sure that the file exists tail -f /tmp/out & pid=$! python test.py kill "$pid" ...
Don't quote the arguments, the args are passed directly to the process without using the shell when shell=False: subprocess.call(["cscope", "-d", "-L0","temp"]) You should use check_call: from subprocess import check_call check_call(["cscope", "-d", "-L0", "temp"]) ...
linux,shell,email,sendmail,boot
Problem in using bash/zsh vs /bin/sh Bash and Zsh have builtin echo with option -e, but a system /bin/echo - not. Compare: /bin/echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n" echo -e "TO:[email protected] \nSUBJECT:System Booted \n\nBeware I live! \n" You may use script like this: #!/bin/sh sendmail -t -vs...
Something like this with grep: grep -vxf lines.txt data.txt > no_dupplicate_lines.txt Sample: AMD$ cat lines.txt Line2 Line4 AMD$ cat data.txt Line1 Line2 Line3 Line4 Line5 AMD$ grep -vxf lines.txt data.txt Line1 Line3 Line5 Print the lines that are not matching (-v) the exact lines (-x) from the file lines.txt (-f...
You can use the $PPID variable to assist you along with a command or two: #!/bin/bash USER=`ps u -p $PPID | awk '{print $1}'|tail -1` echo $USER ...
Executable files may be scripts (in which case you can read the text), or binaries (which are ELF formatted machine code). Your shell script is a script; git is an ELF binary. You can use the file command to see more detail. For example, on my nearest Linux system: $...
As Etan Reisner pointed use double quotes in the puts command instead of braces, so that it will get replaced. puts ${file_id} " root_image=node-${env(os1)} if {[string first r ${env(os1)}] == 0} { create_node_byid 1 [string range ${env(os1)} 0 4]-64 } else { create_node_byid 1 [string range ${env(os1)} 0 5]-64 }...
See docs.ggplot2.org/0.9.3.1/geom_bar.html. It expects the mapping first, then the data. And you don't actually have to specify df for the data, because it's already been captured in g. And I think you need to specify stat='identity' if you want to specify a y aesthetic....
You could do this ... #!/bin/sh set -x cd /WORKING_DIRECTORY make clean make mrproper make VARIANT_DEFCONFIG=msm8974_sec_hlte_spr_defconfig msm8974_sec_defconfig SELINUX_DEFCONFIG=selinux_defconfig make ...
Try doing it using find and for: for file in `find . -type f -name "*.sh"`; do sh $file; done Use can also store it in array and do it: array=($(find . -type f -name "*.sh")) for file in ${array[@]};do sh $file; done ...
Just an idea, I didn't see this anywhere but: Unless you're using full paths to invoke those binaries, you could create mocks of those libraries, e.g., in your projects bin/ directory and make that directory be the first in your $PATH. export PATH="$PWD/bin:$PATH" To mock grep, for example, you could...
You need to dig into the Windows SDK headers to see how large the type is. For example, for a 64 bit process, sizeof(HWND) is 8 in C++ and sizeof(int) is 4 in C# therefore if you use int to store HWND, you are corrupting memory. Same for HKEY, LPITEMIDLIST,...
Try this: find . -mmin +35 -or -mmin -25 find supports several logical operators (-and, -or, -not). See the OPERATORS section of the man pages for more details. ==================== EDIT: In response to the question about processing the two matches differently, I do not know of a way to do...
In x="1 2 3" for i in $x what you are doing is for i in 1 2 3:. But in second case doing xm=`cat $x` ym=`cat $y` This might lead to error saying No such file or directory is the echo $x and echo $y file does not exit....
bash,shell,sorting,matching,file-handling
#!/bin/bash # If there are no files match File_*.*.txt # replace File_*.*.txt by empty string shopt -s nullglob for i in File_*.*.txt; do echo "processing file $i" IFS="_." read foo num1 num2 foo <<< "$i" printf -v dir1 "Dir_%03d" "$num1" printf -v dir2 "Dir_%03d" "$num2" mkdir -pv "$dir1" "$dir2" cp...
Please make a search before you ask any question many posts are already there You can try something like below, modify accordingly Input [[email protected] tmp]$ cat input.txt 1 3 2 5 3 4 4 3 5 2 6 1 7 3 8 3 9 4 10 2 11 2 12...
According to the bash manual, an operator is: A control operator or a redirection operator. See Redirections, for a list of redirection operators. Operators contain at least one unquoted metacharacter. The metacharacter is basically any character that cannot be part of a word. Definition of word: A sequence of characters...
su doesn't enter an interactive session when in a non-interactive session the way it does in an interactive session. In a shell script you get to run a single command in the su context su <user> <command>....
This worked: eval python pgm32.py $args More details on Setting an argument with bash Thanks @Barmar....
You should use a subshell to put the output of the command in mc, not a comma that executes the command and writes its output to stdout after mc has been assigned something and before you write mc to stdout: #!/bin/sh mc=XX:XX:XX:XX$(dd bs=1 count=2 if=/dev/random 2>/dev/null |hexdump -v -e '/1...
You have additional spaces at the declaration of IS_RUNNING. Try IS_RUNNING="$(lsof...)" ...
Assuming that your document is well-formed, i.e. <b> opening tags always match with a </b> closing tag, then this may be what you need: sed '[email protected]<[/]\?b>@\n&\[email protected]' path/to/input.txt | awk 'BEGIN {buf=""} /<b>/ {Y=1; buf=""} /<\/b>/ {Y=0; print buf"</b>"} Y {buf = buf$0} ' | tr -s ' ' Output: <b>data1</b>...
Many tools interpret a - as stdin/stdout depending on the context of its usage. Though, this is not part of the shell and therefore depends on the program used. In your case the following could solve your problem: myprog -o - input_file ...
python,linux,shell,command-line
You need to read stdin from the python script. import sys data = sys.stdin.read() print 'Data from stdin -', data Sample run - $ date | python test.py Data from stdin - Wed Jun 17 11:59:43 PDT 2015 ...
You can redirect commands to karaf like: ./sudo karaf < echo 'feature:install' But I wouldn't recommend you to do that. You see shell will pass the command imidiatelly to karaf which isn't ready to accept those commands (I assume it takes some time for karaf to initialize itself) Instead you'd...
With GNU grep: grep -oP 'aaa&\K.*' file Output: 123 456 \K: ignore everything before pattern matching and ignore pattern itself From man grep: -o, --only-matching Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line. -P, --perl-regexp Interpret PATTERN as a...
The 'grep' command uses a regular expression to match text. Use a '^' before the expression, to match from the start of the line. So, you can change the line name=$(echo $hello | cut -d' ' -f9 | grep $1) to name=$(echo $hello | cut -d' ' -f9 | grep...
when i run my code i get the following ./todo.sh: line 25: syntax error near unexpected token else' ./todo.sh: line 25: else' You must use parentheses to define a shell function, but they have no part in calling one. A shell function is invoked just like any other command:...
I'm not willing to wade through your whole question (sorry, IMHO it's just too long with too much extraneous information) but it looks like you're trying to extract the individual fields from that "confile1" at the top of your question so maybe this is all the hint you need: $...
Store all the arguments in an array: args=("[email protected]") Then print them as: printf "%s\n" "${args[@]}" ...
anubhava's solution is excellent if, as they do in your example, the extensions sort into the right order. For the more general case, where sorting cannot be relied upon, we can specify the argument order explicitly: for f in *.ext1 do program "$f" "${f%.ext1}.ext2" done This will work even if...
bash,shell,unix,random,passwords
#! /bin/bash chars='@#$%&_+=' { </dev/urandom LC_ALL=C grep -ao '[A-Za-z0-9]' \ | head -n$((RANDOM % 8 + 9)) echo ${chars:$((RANDOM % ${#chars})):1} # Random special char. } \ | shuf \ | tr -d '\n' LC_ALL=C prevents characters like ř from appearing. grep -o outputs just the matching substring, i.e. a...
The simplest way to do it is to trap the Ctrl+C signal to do nothing but pass the control to the shell script again. I tried the below code and it worked for me. Replace the sleep commands by the real commands you want to execute. #!/bin/bash #Trap the Ctrl+C...
This will print a dot to the screen every second. Add these lines just before the first snmpwalk command. while true; do echo -n . ; sleep 1 ; done & pid=$! #do time consuming tasks here Then to stop printing the dots, add this line just after the last...
Just use the following line in your batch file: adb shell am instrumentation that will connect to the shell on the Android device and run the am command....
Try something like this and just quit the editor when you finish editing each group of files? while IFS= read -r dir; do files=() while IFS= read -r -d '' xmlfile; do files+=("$xmlfile") done < <(find "$dir" -name "*.xml" -type f -print0) open -W "${files[@]}" done < <(awk '{print $2}'...
You can use it with ssh and heredoc like this: ssh -t -t [email protected]<<'EOF' sed 's~out_prefix=orderid ^2\\\\d\\+ updatemtnotif/~out_prefix=orderid ^2\\\\d\\+ updatemtnotif_fr/~' ~/path/to/file exit EOF PS: It is important to quote the 'EOF' as shown....
In Bash you can do this: #!/bin/bash declare -a varA varB while IFS=$'\t' read -r num first second;do varA+=("$first") varB+=("$second") done <file echo ${varA[1]} ${varB[1]} You can access each element of varA array using index ${varA[$index]} or all of them at once with ${varA[@]}....
shell,command-line,awk,terminal
If order is not important, join and awk can do the job easily. $ join <(sort input.txt) <(sort mapping.txt) | awk -v OFS="|" '{for (i=3;i<NF;i++) print $2, $i OFS}' 103823054|001| 103823044|011| 103823044|012| 103823044|013| 103823064|011| 103823064|012| 103823064|013| ...
I'm not sure what operations you're talking about, but in general, more complex processing systems like R use more complex internal data structures to represent the data being manipulated, and constructing these data structures can be a big bottleneck, significantly slower than the simple lines, words, and characters that Unix...
Bash regex doesn't have lookaround, you can use Perl Regex with grep: #!/bin/bash if grep -oP '^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$' <<< "$1" >/dev/null 2>&1;then echo valid else echo invalid fi ...
BASH_SOURCE cannot be used in .zshrc, because it is a bash-specific variable that isn't defined in zsh. You'll have to replace it with its zsh equivalent, found here.
The usual trick is to copy the function you want to override, and then invoke the copy from within the override: functions --copy ls saved_ls function ls saved_ls end You can't do this in an autoloading ls.fish file since it would result in an infinite loop, but you can do...
GET-parameters are accessed via $_GET-variable. Notice the underscore before the "GET". http://php.net/manual/en/reserved.variables.get.php...
I would store the output of find, and if non-empty, echo the line break: found=$(find . -name "${myarray[i]}") if [[ -n $found ]]; then { echo "$found"; echo "<br>"; } >> "$tmp" fi ...
bash,shell,vagrant,vagrantfile,phppgadmin
First, you need to force htpasswd to read passwords from stdin. It can be done by supplying -i switch. Second, you need to pass a string into htpasswd stdin. This can be achieved in numerous ways. For example you can redirect stdout of echo into stdin of htpasswd. So resulting...
regex,linux,shell,unix,replace
You can do it using awk as: awk '/\[x/{f=1} {if(f)printf "%s",$0; else print $0;} /y\]/{print ""; f=0}' Output: [x data1 data2 data3 data4 y] [a data5 data 6 data7 data 8 b> [x data y] You can also simplify to: awk '/\[x/,/y\]/{ORS=""; if(/y\]/) ORS="\n";}{print}' Output: [x data1 data2 data3 data4...
python,shell,jenkins,continuous-integration
I suspect nosetests will return a non zero value on failure so you can set the shell to auto fail with set -e or any of the other options in here...
python,windows,shell,command,virtualenv
You can activate your virtualenv and then start server using a bat file. Copy this script in to a file and save it with .bat extension (eg. runserver.bat) @echo off cmd /k "cd /d C:\Users\Admin\Desktop\venv\Scripts & activate & cd /d C:\Users\Admin\Desktop\helloworld & python manage.py runserver" Then you can just run...
From: http://www.dzone.com/snippets/execute-unix-command-nodejs To execute shell commands: var sys = require('sys') var exec = require('child_process').exec; exec('command', function (error, stdout, stderr) {}); From: Run shell script with node.js (childProcess), To run a program bar.sh in your home folder with the argument 'foo': var foo = 'foo'; exec('~/bar.sh ' + foo, function (error,...
Did you have a look to this solution? Jenkins: How to use a variable from a pre-build shell in the Maven "Goals and options" Using a shell pre-build step + the InjectEnv plugin, you should be able to solve your problem. Update from June 22nd, I add some screen copies....
php,mysql,database,shell,command-line-interface
You can run mysqldump -h yourhostname -u youruser -p yourdatabasename > C:\your\file\path.sql -h connects you to the remote servers IP so you can dump the data locally, as long as your user has the correct privileges and you can connect remotely to your database server. However, you may need to...
As pointed-out in the comments (hat tip to @anubhava), the OP isn't using bash for the actual script. The shebang must be #!/bin/bash to use the correct shell....
You shouldn't use at sign @ near the second for loop. @ should be used at the beginning of the whole shell command. The following worked for me: DIR= Sources \ Sources_2 all: @for entry in ${DIR}; \ do \ for i in $${entry}/*.c; \ do \ echo "Processing $${i}";...
bash,shell,curl,command-line,pipe
Try this: curl --silent "www.site.com" > file.txt ...
awk -F'|' '{for(i=1;i<=NF;i++)if(!($i%3))print $i}' file this awk one-liner shoud do. With your example, the cmd outputs: 3 6 9 ...
database,shell,docker,docker-compose
The solutions I have found are: docker run tomdavidson/initdb bash -c "`cat initdb.sh`" and Set an ENV VAR equal to your script and set up your Docker image to run the script (of course one can ADD/COPY and use host volumes but that is not this question), for example: docker...
sql,postgresql,shell,hadoop,sqoop
I solved the problem by changing my reduce function so that if there were not the correct amount of fields to output a certain value and then I was able to use the --input-null-non-string with that value and it worked.
You can find like this. File file = new File("data/pattern.txt"); Pattern pat = Pattern.compile("subclass \"Pool1\" 11:22:33:44:55:66 \\{\\s*dynamic;\\s*\\}"); String content = Files.lines(file.toPath()).collect(Collectors.joining("\n")); Matcher m = pat.matcher(content); while (m.find()) { System.out.printf("found at %d-%d%n", m.start(), m.end()); } ...
You could use output redirection cat newtodo.txt > todo.txt <br> or You could rename newtodo.txt mv newtodo.txt todo.txt ...
javascript,node.js,shell,require,node-modules
As per issue #5431, looks like the Node.JS REPL doesn't find globally-installed modules and this is expected behaviour. In the article linked from that issue, it reads: If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your...
In awk Just sub for those fields awk -F, -vOFS="," '{sub(/^[^\.]+$/,"&.",$6);sub(/^[^\.]+$/,"&.",$11)}1' file or sed sed 's/^\(\([^,]*,\)\{5\}[^.,]\+\),/\1./;s/^\(\([^,]*,\)\{10\}[^.,]\+\),/\1./' file ...
As you are on Ubuntu, you likely already have ImageMagick installed - convert, identify and mogrify commands, amongst others. So, make a copy of your data and try something like this on a copy: mogrify -resize 640x480 -unsharp 6x3+1+0 *.jpg or maybe this mogrify -resize 1024x768 -sharpen 0x1.0 *.tif to...
shell,haskell,command-line-arguments,executable
The documentation for readProcess says: readProcess :: FilePath Filename of the executable (see RawCommand for details) -> [String] any arguments -> String standard input -> IO String stdout When it's asking for standard input it's not asking for a file to read the input from, but the actual contents of...
Finally I managed to install it by deleting eclipse luna and downloading it again from scratch... I still don't understand why I got the errors in my old eclipse... It is rather annoying since I had a lot of plugins installed in my old eclipse and I had to re-install...
linux,shell,sed,grep,pattern-matching
The -v option to grep inverts the search, reporting only the lines that don't match the pattern. Since you know how to use grep to find the lines to be deleted, using grep -v and the same pattern will give you all the lines to be kept. You can write...
Apparently the manual entry clearly states: The -n and -v options are non-standard and their use in scripts is not recommended. In other words, you should mimic the -n option yourself. To do that, just check if the file exists and act accordingly. In a shell script where the file...
try this: cat path_to_your_log_file|awk '{split($2,res,":");var=res[1]":"res[2]":"res[3];counter[var]+=$1}END{for(i in counter){print counter[i],i}}' ...
Using sqlite3 from bash on OS X seems fairly straightforward (I'm no expert at this, by the way). You will need to find out which table you need. You can do this with an interactive session. I'll show you with the database you suggested: /Users/fredbloggs> sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db SQLite version...
Do you want see route for ether0, you can use below command ip -o route show dev ether0 or ip route show | grep ether0 or route -n | grep ether0 or netstat -nr | grep ether0 To see NIC for ether0, you can use ifconfig command and Gateway NIC...
The most common issue when handling variables containing paths of directories and files is the presence of special characters such as spaces. To handle those correctly, you should always quote the variables, using double quotes. Better code would therefor be: sudo sh "$path/join.sh" sudo sh "$path/join2.sh" It is also advised...
This script will get called and passed a customer number. myEmailFinder "$CustID" I want to populate a variable based on the passed in customer number. emailAddr=$( myEmailFinder "$CustID") I want to pull an e-mail associated with that customer number and populate a variable with it. I would prefer this...
It is caused by shell not performing variable expansion on the left side of the redirection operator. You can use a workaround: eval exec "${PIPE_ID}"'<>"spch2008"' It will force the shell to do variable expansion, producing eval exec 100'<>"spch2008"' Then the eval built-in will feed the command to the shell, which...
Try this to create a string variable n, with no leading whitespace (thanks @011c): n="10.0.0.135.527" wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa.products.ldm.ingestion.server.scala/"$n"-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-"$n"-20150622.210643-1-sources.jar ...
From what I understand I would recommend you look in to Applescript as this will allow you to have a GUI Interface as well as executing 'SHELL' commands. First of all I would open 'Script Editor' program that comes preinstalled on Mac's This is an example script which asks for...
linux,bash,shell,command-line,tee
Hard coded solutions tee Echo nothing and simple send it to multiple files using the tee command. Like this: $ echo -n | tee file1 file2 file3 file4 file5 All files in that list will be empty and created if they don't exist. Applied to your answer this would be:...
For Checking Diretory is present if [ -d "$YOUR_DIRECTORY" ] then #Operation when directory is present else #Operation when directory is not present fi For checking if directory is writeable if [ -w "$YOUR_DIRECTORY"] then #Operation when directory is writeable else #Operation when directory is not writeable fi Regarding Oracle...
in the loop, test if file exists before calling a program operating on that file: for i in $(seq 0 100); do INPUT=c2.$(($i*40+495)).bin test -e $INPUT && ./f.out $INPUT c2.avg.$(($i*40+495)).txt done This way the ./f.out ... will be executed only for existing input files. See man test for details. BTW,...
I'd rewrite that as: #!/bin/bash while read -ra hello; do name=${hello[8]} if [[ $name == "$1"* ]]; then log=${hello[2]} echo "$log $name" fi done | column -t read -ra splits the input line and stores the words in the "hello" array. [[ $name == "$1"* ]] is a built-in way...
python,shell,profiling,ipython,ipython-magic
From the ipython example in the pyprof2calltree documentation: >>> from pyprof2calltree import convert, visualize >>> visualize('prof.out') >>> convert('prof.out', 'prof.calltree') Or: >>> results = %prun -r x = taylor_sin(500) >>> visualize(results) >>> convert(results, 'prof.calltree') You could also try: >>> %run -m pyprof2calltree -i prof.out -o prof.calltree ...
Use upgrade_oh_my_zsh upgrade to the latest version. This issue fix here...
Yes, use the -S switch which reads the password from STDIN: $echo <password> | sudo -S <command> Exposing your password is generally bad idea search for something that can protect / hide it. In the past I've used Jenkins plugins to do this while executing the scripts regularly....
A for loop in shell scripting takes each whitespace separated string from the input and assigns it to the variable given, and runs the code once for each value. In your case b* is the input and $var is the assigned variable. The shell will also perform expansion on the...
You can use the following query to produce the required result set: SELECT KID, MAX(CASE WHEN REDO = 1 THEN REV) AS REDO1, MAX(CASE WHEN REDO = 2 THEN REV) AS REDO2 FROM Table1 GROUP BY KID The above uses conditional aggregation in order to place all REV values that...
Are you saying that you want to detect when 5 consecutive rows contain a value greater than 200? If so: awk '{a = $1 > lim ? a + 1 : 0} a > seq {print "alert on line " NR}' lim=200 seq=5 input It's not clear what you actually...
The mongo shell, as well as the mongod database process are implemented in C++. You can get the source code and build it yourself here: https://github.com/mongodb/mongo
linux,shell,command-line,awk,sed
Almost same as the other answer, but printing 0 instead of blank. AMD$ awk -F, 'NR>1{a[$2]+=$3;b[$2]++} END{for(i in a)print i, a[i], b[i]}' File pear 1 1 apple 2 3 orange 0 1 peach 0 1 Taking , as field seperator. For all lines except the first, update array a. i.e...
You can use below script #!/bin/bash USER=root PASS=root123 mysqladmin -h remote_server_ip -u$USER -p$PASS processlist ###user should have mysql permission on remote server. Ideally you should use different user than root. if [ $? -eq 0 ] then echo "do nothing" else ssh remote_server_ip ###remote server linux root server password should...