Posts mit dem Label bash werden angezeigt. Alle Posts anzeigen
Posts mit dem Label bash werden angezeigt. Alle Posts anzeigen

Freitag, 10. Oktober 2014

remove zero sized file

To delete zero sized files in bash you can simply use an if clause with you can put in a loop. First the if clause

  if [ ! -s file ] ; then
    rm file
 fi

and finally the full loop:

 for file in *
 do
   if [ ! -s $file ] ; then
     rm $file
   fi
 done

Donnerstag, 12. Dezember 2013

Bash combining files

Combine files side by side columnwise:

If you have two files one of them consisting of one column and another file consisting of one column as well you can join the files by using:
paste file1 file2

Combine files one after the other:

Simply use:
cat file1 file2
which will first print file1 and then file2.

The "join" command:

Additionally there is also the join command which will print data which is present in file1 and file2, e.g.:
join file1 file2
If file1 and file2 share the same string in one line it gets printed to standard out.

Mittwoch, 11. Dezember 2013

Periodically execute program (bash) - watch

To periodically execute a command, e.g. ll to see the change in files just use watch:
watch  [-n <seconds>] [--differences[=cumulative]] [--interval=<seconds>] <command>
For example like this:
 watch ls -l

Montag, 9. Dezember 2013

Gnuplot write in a variable from bash

If you want to read in a variable, which is in a file for example or you simply have a script to calculate it into gnuplot. Simply use the following command:

 variable="`BASH COMMAND`"

instead of BASH COMMAND you can use any bash command you like and even load variables or get data from files, e.g.:

 variable="`echo $VARIABLE`"

Montag, 16. September 2013

bash "--" = no more options

This one is a bash tweak! If you need to tell a bash script, that there are no more options to come you can just add -- after all comments.
This is especially helpfull if a keyword after that has to start with a minus.

 rename -- -help help *  

renames the -help into help in all files.

Sonntag, 28. Juli 2013

Hi

Hi,

I am a graduate student in the field of theoretical chemistry and with this blog I mostly just want to remember all the hacks I did for Gnuplot, Latex and all the other scripting languages I use.

Additionally I probably will put up a few setup files for gnuplot, latex, vmd, emacs and so on.

So if you are interested in that keep on looking =)

Best,

Koni