Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Tuesday, October 19, 2010

Merging several PDF files in Linux

I often google on "How to merge multiple files into a single PDF". Well, it is quite a simple task to put together, or combine, PDF files without installing "Pdftk". All you need is just the GhostScript package. Here is a sample command taken from one of my bash-scripts:

#!/bin/bash
gs \
    -dBATCH \
    -dNOPAUSE \
    -q \
    -sDEVICE=pdfwrite \
    -r600x600 \
    -sPAPERSIZE=a4 \
    -sOutputFile=merged-file.pdf \
    file-1.pdf \
    file-2.pdf \
    file-3.pdf

Sunday, November 8, 2009

How to fix some sort of mp3-files

#!/bin/bash

# 
# I had some mp3-files that were repeated twice inside themselfes.
# It looked like someone copied them one day with append command.
# The script splits such files into to equal parts and checks if
# those parts are coinside.
#

for f in *.mp3 ; do
    # Calculate size of the file
    size=`du -b "${f}" | cut -f 1`
    half_size=`echo ${size}/2 | bc`

    # Split file into two parts
    f1="$f".1
    f2="$f".2
    head -c $half_size "$f" > "${f1}"
    tail -c $half_size "$f" > "${f2}"

    # Calculate checksums and check if they coinside
    md1=`md5sum "${f1}" | cut -f 1 -d " "`
    md2=`md5sum "${f2}" | cut -f 1 -d " "`
    if [ ${md1} != ${md2} ] ; then
        echo "Problems with $f"
    fi
done