Tag Info

New answers tagged

0

Perlishly, I'd be thinking: use strict; use warnings; local $/; my $slurp = <DATA>; $slurp =~ s/\b(\w+)\W\1/$1/go; print $slurp; __DATA__ Hi! Hi, same same? word twice twice, as as here here! ! ,123 123 need need as here Bear in mind though - a lot of pattern matching is line oriented, so you've got to be careful if you cross line boundaries. If ...


2

With GNU grep: echo 'Hi! Hi, same word twice twice, as as here here! ! ,123 123 need' | grep -Eo '(\b.+\b) \1' Output: twice twice as as here here 123 123


0

You shouldn't need the cygdrive if you have your mount table set up correctly. Try: cp /c/Users/JohnSmith/Downloads/cs184-john-stanford-edu.pem . With the following mount table: $ mount C:/cygwin/bin on /usr/bin type ntfs (binary,auto) C:/cygwin/lib on /usr/lib type ntfs (binary,auto) C:/projects on /projects type ntfs (binary) C:/cygwin on / type ntfs ...


2

Is it because no new files have been downloaded,[...]? Yes. That's it. There will be no summary if zero bytes have been downloaded. It's because of the second half of the if-statement below: "total_downloaded_bytes != 0" Source from the wget Git repo: if ((opt.recursive || opt.page_requisites || nurl > 1 || (opt.input_filename ...


0

I had the same problem with tmux and patched it with reattatch-to-user-namespace and shell aliases. $ brew install reattach-to-user-namespace $ vi ~/.bash_aliases alias subl='reattach-to-user-namespace subl' alias stree='reattach-to-user-namespace stree' alias open='reattach-to-user-namespace open' $ source ~/.bash_aliases Not elegant, but works.


1

How about this command? tac file| awk '/---/ {exit} {print}'|tac From man tac: tac - concatenate and print files in reverse - reverse of cat command ;) Output of tac file: next line this is a test to add some extra content --- draft: true title: dont't know --- The awk command awk '/---/ {exit} {print}' prints all lines until first matched pattern ...


1

less also recognizes start-of-line anchor ^ and greedy matching operator *. man -P "less '+/^ *'pushd" bash manbb() { man -P "less '+/^ *'${1}" bash } manbb pushd


0

To change the ownership: sudo chown root:root /usr/backup/mysql/db-backup.sh To run at midnight using crontab, run sudo crontab -e. That will open a file in an editor. Add the following line to the bottom of the file and save the file: 0 0 * * * /usr/backup/mysql/db-backup.sh The script will now run at midnight every night.


0

Consider using rsync to automatically copy files from the proxy to the destination: rsync local-file user@remote-host:remote-file


0

This works: #!/bin/bash results=($(mysql --user root -pwelcome ts -Bse "SELECT type, network_id, subnet_msk FROM remote_subnet;")) cnt=${#results[@]} for (( i=0 ; i<cnt ; i++ )) do echo "Record No. $i: ${results[$i]}" fieldA=${results[0]}; fieldB=${results[1]}; fieldC=${results[2]}; done


0

#! bin/bash query="select * from test;" myarray=$(mysql -h hostname -u user -ppass database << eof $query eof) echo $myarray


1

How about a function in you .bash_profile scps () { if [ -f $1 ] ; then scp $1 davea@proxy:/home/davea && ssh davea@proxy && scp $1 davea@server:/home/davea else echo "'$1' is not a valid file!" fi } Then you can use scps filename to copy filename to davea@server:/home/davea.


0

!/bin/sh look=`which find` BACKUPLOCATION="/backup" TODAYDIR=`date +%d-%b-%Y` DELDIR=`date -d "-7 day" +%d-%b-%Y` echo "Backup Deleting For Date : $DELDIR" $LOOK $BACKUPLOCATION -type d -name $DELDIR -exec rm -rf {} \; 2>/dev/null echo "Backup Deleted Successfully...!" exit 0; Above script is to delete backup folders created 7 days before. Run this ...


2

from a linux system (man ps): D uninterruptible sleep (usually IO) R running or runnable (on run queue) S interruptible sleep (waiting for an event to complete) T stopped by job control signal t stopped by debugger during the tracing W paging (not valid since the 2.6.xx ...


0

If you set the shell variable PROMPT_COMMAND to a command, then that command will be executed every time the shell is about to issue a (primary) prompt.  For example, % ls file1 file2 % PROMPT_COMMAND=date Thu, Nov 20, 2014 1:23:42 PM % ls file1 file2 Thu, Nov 20, 2014 1:23:45 PM % This can be a program, a script, or whatever.


0

Funnily enough, Ctrl+C is what you are looking for. when you are on $ echo "foo bar > baz > just press Ctrl+C (edited command line will suspend) and press Up (previous-history). Your prompt will be: (note the absence of >) $ echo "foo bar baz Now you can move around with Left Right even through line jumps. There is only one quirk, you must be ...


0

I had a similar occurrence, however, mine was sudo: rm: command not found This was caused by incorrectly altering the path in ~/.bash_profile


0

I don't know if you want to print just final summary to file from some period you are going to monitor network activity, but you can cheat it this way: vnstat -l -i <device> >> dump.txt The only issue is that vnstat will write output to file every second so it is not the most convenient way. For continuous monitoring with log for every second ...


-1

Addressing one aspect of your (now original) question. (And your new questions stills talks about grep and -A1 and pretends that you can't find a way to specify 3 hiphens and that's just wrong because in your comments you've shown that you can). [your original question asked how to show results FROM a point. when actually you want FROM AFTER. Your new ...


1

$ line=$(grep -n -- --- test.info | tail -n 1 | cut -d: -f1);tail -n +$(( $line + 1 )) test.info this is a test to add some extra content Appropriate error checking needs to be added, as in if $line 'not numeric' ... The original problem comes from the fact that you need to escape - or tell the program that it is not an option: $ grep -n -- --- ...


0

I see at least two different ways to do it. In fact you need to escape the first "-" Using option -e: grep -e "---" test.info Escaping the first "-" with backslash: grep "\---" test.info


2

#!/bin/bash plugins=(Plugin1 Plugin2 Plugin3) plugin_cmd="#!/bin/bash\necho This is plugin __placeholder__\n" for plugin in ${plugins[@]}; do echo -e ${plugin_cmd/__placeholder__/$plugin} > /tmp/${plugin}.bash chmod +x /tmp/${plugin}.bash screen -dmS $plugin screen -S $plugin -X stuff "/tmp/${plugin}.bash\n" screen -d -r -S $plugin ...


2

Bash has its own testing syntax, where you can use > and <: $ val1=2013-12-31T00:00:00 $ val2=2014-11-19T15:40:30 $ [[ $val1 > $val2 ]] $ echo $? 1 $ [[ $val1 < $val2 ]] $ echo $? 0 Alternatively you can use Unix timestamps and compare the integer values: $ val1=$(date --date='2013-12-31T00:00:00' +%s) $ val2=$(date ...


0

There is /etc/hosts~orig - original hosts file. So you can just ➜ ~ sudo cp /etc/hosts\~orig /etc/hosts


0

How about writing the PIDs and output status to a temp file, e.g. via 'mktemp'. After finishing a TEST and checking its status, simply delete the temp file and create a new one when the next TEST runs. Or keep all the temp files for later reference and check the timestamps of the temp files to get the one related to the currently running TEST.


0

To get the exit code for a background process, use wait: $ (sleep 1; false) & pid_1=$!; (sleep 1; true) & pid_2=$! [1] 29111 [2] 29112 $ wait $pid_1 $ echo $? 1 $ wait $pid_2 $ echo $? 0


0

This is typical work I used to do using Foobar2000. Works good enough under Wine. Open the files into Foobar2000, open the context menu and look for "Tagging", "Manage Scripts". Then look for action "Guess values from filenames". As guessing pattern took something like "%artist%\%album%\%tracknumber% - %title%", if for exmaple your files (named with ...


0

I do something like this, although I'm not adding in the same information (all I'm adding is album art.) You need the package eyeD3. For my particular use, I use the following command line (I incorporate it into a bash script, you could certainly use python): eyeD3 --genre= --to-v2.3 --no-tagging-time-frame --remove-comments ...


0

On Windows you can use Mp3tag: free, batch process, and tagging following the filename.


3

The following tests whether the local timezone has changed since yesterday: [ "$(date -d "yesterday" '+%z')" = "$(date '+%z')" ] The %z format asks date to return the timezone. The above compares the result for today versus the result for yesterday. How to use it The test command can be used to control statement execution: $ [ "$(date -d "yesterday" ...


0

Dopn’t panic! The file /bin/sh is simply a binary file for the shell on the system which is bash. Here is the output of me running /bin/sh -version on my Mac OS X 10.9.5 (Mavericks) install: GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin13) Copyright (C) 2007 Free Software Foundation, Inc. Your removal of it is one thing, but if it was damaged ...


0

I use this: PATH=$PATH:"$HOME/Documents/Android/SDK/platform-tools" Previously I had to use this to work (re-installed the OS X/ZSH and the problem disappeared): export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:$HOME/Documents/Android/SDK/platform-tools"


1

Why so complicated? pkill -f proxy Here, pkill takes an argument named -f to search for a pattern in the process name (more specifically, /proc/pid/cmdline). You can also tell it to use another signal as in pkill -9 -f proxy. Other than that you want to use a shell function with one parameter – but this is very simplistic and may result in a lot of ...


0

To execute a bash script issue 'chmod +x xxx.sh' where xxx.sh is your script filename, then issue 'sh xxx.sh'. That should do the work for you...


3

You are correct that the substitution occurs when PATH is defined. It is simple to get around that. Define a bash/zsh function: javaswitch() { [[ "$1" =~ ^[0-9]$ ]] && export PATH=${PATH/java[0-9]/java$1}; } Now, anytime that you want to switch java versions, run: javaswitch 7 Or: javaswitch 8 To make the definition of javaswitch ...


0

As someone mentioned in a comment, it all depends on the application. It would need to be written to accept a file as an argument/parameter when running it. There are multiple ways to pass a file into an application, but it depends on how it is written.


0

Ok, and now for the serious answer ;-) (I discovered this seconds after I had poster my original answer. But I'm still keeping the old answer, just for fun.) I think you could use this: https://powerline.readthedocs.org/en/latest/usage/shell-prompts.html#bash-prompt. Disclaimer: I haven't tested it!


0

Cool question. To my knowledge, this can't be done with Bash alone, as David Postill said. But as he suggested, you could (ab)use the prompt for this purpose. Here's an example using ANSI escape sequences to achieve the effect of a status bar :-) PS1='\[\e[s\e[1;1H\e[41;1m\e[K\e[33;1m\][ *** \t *** ]\[\e[0m\e[u\]\w> ' This one just displays the current ...


0

One solution that would handle both local and remote (over ssh) hosts would be rsync: rsync -av -n -c src/ dst/ The -n flag tells rsync not to actually do any transfers - so the output would be just the files that it wants to transfer, or, the changed files. The -c ensures that rsync does an MD5 comparison. If you want to just do a match against size and ...


0

The command—in and of itself—you are showing as an example is correct will work: echo "This is my body" | mail -s"this is my header" thisis@my.mail But you need to have some kind of local MTA (mail transfer agent) installed on the Linux machine you are attempting to do this on before it can work. On Ubuntu setting this up is as simple as installing ...


0

You can try mutt command as follows according to this site: echo "<message body>" | mutt -s "<subject>" -a "<optional attachment>" -e "my_hdr From:<from address>" -- <recipients list separated by space>


0

This should work using eval as well as locate coupled with $() like this: eval $(locate nasm_shell) But the risk with using this is let’s say you have multiple files with the name nasm_shell on the system. Then that command would fail since it would attempt to try and run the full output of the locate command. But if you are 100% positive what you are ...


2

$(locate nasm_shell) or `locate nasm_shell` You can use backticks `` or $() to execute the command in a subshell, for instance: user@host$ which df /bin/df user@host$ `which df` Filesystem 1K-blocks Used Available Use% Mounted on ... /dev/sda1 498532 199535 268738 43% /boot /dev/mapper/vg-home 412718256 232104076 ...


0

You should try: screen -t $plugin xterm & instead of your version. screen opens a new shell, inside which you will be trapped, without any possibility to continue the do loop; thus the ampersand makes sure that control is immediately returned to the do loop, while xterm (or konsole, or whatever you like) gives a place, so to speak, where screen is ...


0

You can find the difference between the environments like this: su <user> printenv su <user> -c "printenv" You can modify the environment in the second case like this: su <user> -c "export <varname>=<varvalue>; <more commands...>" Now for the specific problem I was having, I discovered that I needed the variable ...


0

The $if mode=vi conditional looks correct. Read .inputrc into bash with: bind -f ~/.inputrc To read the bash help for bind: help bind AFAIU, echo is not a valid inputrc command. Here are the Bash readline docs: https://www.gnu.org/software/bash/manual/bashref.html#Readline-Init-File


0

After searching for the exact error I found that this was answered at AskDifferent: http://apple.stackexchange.com/questions/153790/how-to-fix-brew-after-its-upgrade-to-yosemite cd /usr/local/Library git pull origin master You can just update everything manually with Git. You can't edit /usr/local/Library/brew.rb in any way though, or you'll get the same ...


1

You can do it with grep cat filename | grep -A1 TWITTER | grep -v TWITTER or, perhaps better, you can do it with awk awk '/TWITTER/{getline; print}' filename


1

Why not generate a custom .screenrc? E.g. if your folder with plugins does not change often then write this to a file. # Setting custom things: startup_message off # starting a few shells with a preselected title screen -t plugin1 0 screen -t plugin2 1 screen -t plugin3 2 screen -t my_email -a -l exec elm If the number of plugin changes ...


1

Here's a skeleton that may be used directly in a bash script: #!/bin/sh psql -U postgres << END_OF_SCRIPT DROP DATABASE sis_db; -- drop the DB CREATE DATABASE sis_db WITH OWNER = postgres ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' CONNECTION LIMIT = -1; \c sis_db -- Create some schemas on the DB ...



Top 50 recent answers are included