The following CLI one-liner prints all the lines between the lines containing PATTERN1 and PATTERN2 (including the lines with these two patterns) in a file, FILENAME:
sed -n '/PATTERN1/,/PATTERN2/p' FILENAME
17 Monday Dec 2012
25 Friday Mar 2011
Resize a picture or PDF file by 50% of its original form and save it as a PDF:
$ convert rose.jpg -resize 50% rose.pdf
Well, ‘convert’ may be used to convert between most of the known image formats —- not just JPG and PDF!
N.B. 1. More options may be found at the ImageMagick website. More information on how to specify the geometry may be found here. (If you don’t have ImgeMagick you need to install it first — see the first link for more information on installation!).
2. Here is a list of other useful options/ examples on how to make the best out of ‘convert’.
3. If you’re at playing with PDFs you may also be interested in joining and removing pages from a PDF document using Ghostscript — see a previous post here.
06 Friday Nov 2009
Tags
awk, formatting, I/O, print, printf
If you use print in awk you’ll lose the formatting of the input file — most of the times that may be OK, but not always. The solution is simple — replace print by printf. Here’s an example with strings in the input fields:
$ awk '{printf "%-20s%-20s%-20s\n", $1, $2, $3}' yourfile.dat.
- “%…s” means a character string.
- 20 means a length of 20 characters.
- awk defaults to right-alignment (presumably for columns of figures) so you need -20 for left-alignment.
Credit: here.
01 Tuesday Sep 2009
Posted in printer
CUPS = Common UNIX Printing System
In order to search for the CUPS based printers connected to the computer (directly or via a network), use this command in the terminal:
lpstat -a
or type in the address field of a browser:
http://localhost:631/printers.
The following file controls the cups configurations:
/etc/cups/cupsd.conf.
Make sure you configure the file as follows:
1. Tell cupsd to listen broadcasts. This can be done by turning Browsing on
Browsing On.
2. Tell cupsd to listen broadcasts from other than local network as well.
BrowseOrder deny,allow.
BrowseAllow ALL
01 Tuesday Sep 2009
Posted in cli
Tags
cli, ghostscript, gs, pdf, print
Combine pdf files:
$ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf pdffile1.pdf pdffile2.pdf
which combines pdffile1.pdf and pdffile2.pdf into a single ouput.pdf.
Delete certain pages of a PDF document:
$ gs -sDEVICE=pdfwrite -dNOPAUSE -dQUIET -dBATCH -dFirstPage=m -dLastPage=n -sOutputFile=output.pdf input.pdf where m and n are positive integers (page numbers), i.e. the above command only prints out pages starting from page number m through n of input.pdf into output.pdf.