Counting regex pattern matches in one line using sed or grep?
You could use grep -o then pipe through wc -l: $ echo “123 123 123” | grep -o 123 | wc -l 3
You could use grep -o then pipe through wc -l: $ echo “123 123 123” | grep -o 123 | wc -l 3
You can easily sort your output, in descending numerical order of the 3rd field: for k in “${!authors[@]}” do echo $k ‘ – ‘ ${authors[“$k”]} done | sort -rn -k3 See sort(1) for more about the sort command. This just sorts output lines; I don’t know of any way to sort an array directly in … Read more
Make sure the shebang on the script points to an interpreter that actually exists. Thus, if the script being invoked uses: #!/bin/bash …then /bin/bash needs to actually be installed. (Alternately, you might consider trying to port the script to work with POSIX sh, and modifying its shebang to /bin/sh).
I decided to write a slightly more detailed explanation. The “magic” here lies in the operating system. Both programs do start up at roughly the same time, and run at the same time (the operating system assigns them slices of time on the processor to run) as every other simultaneously running process on your computer … Read more
You are checking for the wrong condition. if [ “$choice” != ‘y’ ] && [ “$choice1″ != ‘y’ ]; The above statement is true when choice!=’y’ and choice1!=’y’, and so the program correctly prints “Test Done!”. The corrected script is echo “- Do You want to make a choice ?” read choice echo “- Do … Read more
You should be able to run the script typing: $ chmod 755 ./scripts/replace-md5sums.py $ ./scripts/replace-md5sums.py There are times where the user you are currently logged with just don’t have the permission to change file mode bits. In such cases if you have the root password you can change the file permission this way: $ sudo … Read more
(Update April 2017 for Git 2.13, Q2 2017) There is now an official command to determine if a repo is a submodule of a parent repo: cd /path/to/potential/submodule/repo git rev-parse –show-superproject-working-tree See commit bf0231c (08 Mar 2017) by Stefan Beller (stefanbeller). (Merged by Junio C Hamano — gitster — in commit 3edcc04, 17 Mar 2017) … Read more
./run_some_process 2>&1 | tail -10 >>logfle tail -10 will give you last ten lines, 2>&1 redirects stderr to stdout, >>logfle appends to logfile.
Fernando Perez, creator of IPython, suggests this: In [1]: %%bash . ~/.bashrc <my_fancy_bash_function> <function_argument> This works on the current stable version (0.13.2). He admits that’s a bit clunky, and welcomes pull requests. . .
You are very close: Change if statement to if ssh username@ssh_server ‘[ -d /directory ]’ I am assuming that you have setup key-based authentication.