Monthly Archives: October 2012

Software Defined Radio

The owner of this blog is currently working on an cheap, open and powerful software defined radio solution called HackRF. This seems to be very exciting.

http://ossmann.blogspot.de/

Merge multiple pdfs into a single file

Ubuntu brings a nice package called “pdftk” for editing pdfs using the command line. This command joins multiple pdfs into a single pdf:

pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

Here is another way to join pdf files, that only requires ghostscript:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=123.pdf 1.pdf 2.pdf 3.pdf

Using the commandline editor “sed” for batch renaming of files

Given a set of files, that all end with “.png.jpg”. We want to remove the “.png” from the filename. This can be done using the linux shell pipes and the commandline editor “sed”.

Examine this command: ls * | sed ‘s/\(.*\)png\.\(.*jpg\)/mv & \1\2/’ | sh

The interesting part here is of course sed ‘s/\(.*\)png\.\(.*jpg\)/mv & \1\2/’. The general syntax is “sed ‘s/patternToSubstitue/SubstituteBy/'”.

  • s means “substitute”
  • \(.*\)png\.\(.*jpg\) This splits the given string into a segment of arbitrary content \(.*\), another segment containing the fixed string “png.” and a third segment \(.*jpg\) consisting of a string with arbitrary content ending with “jpg”. The first and third part are dynamically created, so sed allows to reference them using \1 and \2
  • mv & \1\2 This part constructs a command that can be executed by the shell. The “&” references the original string passed into sed, the parts \1 and \2 are generated above and concatenated.

The result of this command is, that the substring “png.” is removed from all filenames in the current directory. Files that don’t match this pattern are not changed, because the mv command gets the same name as source and target file.

Imagemagick for batch processing of images

Imagemagick can apply a number of different filters at a time. In combination with the linux pipes it is possible to batch process a huge number of images.

The command below takes all images in the “data” directory and does the following steps:

  • Resize to 400×300 pixels
  • Transform to gray color
  • Apply a sepia effect to give the image an “old” style
  • Change (brightness,saturation,hue) from (100,100,100) to (100.35,100)

ls data/ | xargs -I {} convert data/{} -resize 400×300 -colorspace gray -sepia-tone 81% -modulate 100,35,100 -quality 60 {}.jpg

Show progress of “dd” process

The “dd” tool is very useful for cloning/backing up/erasing partitions and harddrives. However all these tasks take a long time and the “dd” command does not output status messages on the screen. You never know how much time the process will need to complete or how much data has already been processed.

Luckily there is a hidden way to get this information. Get a command prompt and enter the command below. Replace “Process-Id” by the id of the “dd” process, which can be obtained by “ps -A”.

kill -SIGUSR1 Process-Id