For example, say I have string like:
duck duck duck duck goose goose goose dog
And I want it to be as sparsely populated as possible, say in this case
duck goose duck goose dog duck goose duck
What sort of algorithm would you recommend? Snippets of code or general pointers would be useful, languages welcome Python, C++ and extra kudos if you have a way to do it in bash.
This is the script I currently have-
#!/bin/bash
if["$#" == "2" OR who | grep ":0" == ""]
export DISPLAY=:0
xset dpms force on
mplayer -fs $1.mp4
fi
It doesn't work.
Thanks for your help.
I need to recursively remove unnecessary files from a svn repository and i have the following batch file to do this:
@echo on
del /s ~*.*
del /s *.~*
del /s Thumbs.db
However, this is also deleting the entries under the .svn/ subfolders. Is there any way to prevent this commands from being executed under the .svn/ folders so that it doesn't mess things up?
Thanks in advance!
EDIT: A solution using Bash (cygwin) would also work for me since i just need to do this once.
I have a script where I do not want it to call 'exit' if it's being sourced. Initially I though checking if $0 == bash but this has problems if the script is sourced from another script, or if the user sources it from ksh. Is there a reliable way of detecting if a script is being sourced?
I have a bash script that runs on our shared web host. It does a dump of our mysql database and zips up the output file. Sometimes the mysqldump process gets killed, which leaves an incomplete sql file that still gets zipped. How do I get my script to 'notice' the killing and then delete the output file if the killing occurred?
xargs is widely used in shell scripting; it is usually easy to recast these uses in bash using while read -r; do ... done or while read -ar; do ... done loops.
When should xargs be preferred, and when should while-read loops be preferred?
Hello i have this line...
"00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter"
how can i get the first numbers until VGA with SED in Bash script?
Thanks!
Hi. I'm trying to do the following in a bash script:
com=`ssh host "ls -lh" `
echo $com
It works, but the echo will break the output (instead of getting all lines in a column, I get them all in a row).
If I do: ssh host ls -lh in the CLI it will give me the correct output + layout.
Any ideas?
Im testing something where im compiling some code and analysing output with a perl script.
So first i run make, manually copy&paste the output to errors.txt and then running my perl script (running: perl analysis.pl) in terminal.
Is there away I can do this just with one line in bash?
xargs is widely used in shell scripting; it is usually easy to recast these uses in bash using while read -r; do ... done or while read -ar; do ... done loops.
When should xargs be preferred, and when should while-read loops be preferred?
I would like to run a backup job on a directory tree from a bash script if any of the files have been modified in the last 30 minutes. I think I can hack together something using find with the -ctime flag, but I'm sure there is a standard way to examine a directory for changes.
I know that I can inspect the ctime of the top level directory to see if files were added, but I need to be able to see changes also.
FWIW, I am using duplicity to backup directories to S3.
Im writing a bash-script to perform an offsite backup, using rsync over SSH. I'm able to send STDOUT to logger, for logs via
rsync --del -az -e 'ssh -i mycrt.crt' /home/gnutt/backup/ me@offisite:backup | logger -i
But I want to send STDERR instead, so if there is a problem, such as that offsite is unavailable, that output should be sent to logger and logged.
I'm using objcopy on bash (ubuntu linux) and im trying to copy 2 sections from an ELF file using the folowing commend:
objcopy -j .section1 -j .section2
The problem is the objcopy is adding some padding between the sections. Is there a way (a flag?) that can stop objcopy from padding the sections?
the sections are placed one after the other in the file so there is no need for any kind of padding....
While taking a look at this awesome thread I noticed that some examples use
PS1="Blah Blah Blah"
and some use
PROMPT_COMMAND="Blah Blah Blah"
(and some use both) when setting the prompt in a bash shell. What is the difference between the two? An SO search and even a bit of broader google searching aren't getting me results, so even a link to the right place to look for the answer would be appreciated. Thanks!
Is there a less brute-force way to do this?
#!/bin/ksh
THIS_SCRIPT=$(/usr/bin/readlink -f $(echo $0 | /bin/sed "s,^[^/],$PWD/&,"))
echo $THIS_SCRIPT
I'm stuck using ksh but would prefer a solution that works in bash too (which I think this does).
I wrote a .sh file to compile and run a few programs for a homework assignment. I have a "for" loop in the script, but it won't work unless I use only integers:
#!/bin/bash
for (( i=10; i<=100000; i+=100))
do
./hw3_2_2 $i
done
The variable $i is an input for the program hw3_2_2, and I have non-integer values I'd like to use. How could I loop through running the code with a list of decimal numbers?
I have a string like this
BRADI5G20430|BRADI5G20430.1||1
How can I replace the bar (single and multiple) with tab ("\t")?
I tried this but dont' work
sed 's/\|+/\t/g'
I also want to include this line in bash script.
Say I have a file of this format
12:04:21 .3
12:10:21 1.3
12:13:21 1.4
12:14:21 1.3
..and so on
I want to find repeated numbers in the second column for, say, 10 consequent timestamps, thereby finding staleness.
and I want to output the beginning and and end of the stale timestamp range
Can someone help me come up with it?
You can use awk, bash
Thanks
I am writing a bash script and need to redirect the stdout and stderr output of a command i run to a single file, prefixing each line with stderr or stdout, accordingly.
is there a simple way to do this?
I have a few directories and sub-directories containing files with no file extension. I want to add .jpg to all the files contained within these directories. I have seen bash scripts for changing the file extension but not for just adding one. It also needs to be recursive, can someone help please?
I'm looking for a quick bash script or program that will allow me to kick off a python script in a separate thread. What's the best way to do this? I know this is incredibly simple, just curious if there's a preferred way to do it.
Hi
with linux bash shell , how can i use regex to get a certain string of a file
by example:
for filename *.tgz
do
"get the certain string of filename (in my case, get 2010.04.12 of file 2010.01.12myfile.tgz)"
done
or should I turn to perl
Merci
frank