Dies ist eine alte Version des Dokuments!
Inhaltsverzeichnis
Shell commands
awk, setxkbdmap
awk
How To Use awk In Bash Scripting
by nixCraft on August 15, 2009 · 29 comments· LAST UPDATED August 14, 2009 see: http://www.cyberciti.biz/faq/bash-scripting-using-awk/
How do I use awk pattern scanning and processing language under bash scripts? Can you provide a few examples?
Awk is an excellent tool for building UNIX/Linux shell scripts. AWK is a programming language that is designed for processing text-based data, either in files or data streams, or using shell pipes. In other words you can combine awk with shell scripts or directly use at a shell prompt.
Print a Text File
awk '{ print }' /etc/passwd
OR
awk '{ print $0 }' /etc/passwd
Print Specific Field
Use: as the input field separator and print first field only i.e. usernames (will print the the first field. all other fields are ignored):
awk -F':' '{ print $1 }' /etc/passwd
Send output to sort command using a shell pipe:
awk -F':' '{ print $1 }' /etc/passwd | sort
Pattern Matching
You can only print line of the file if pattern matched. For e.g. display all lines from Apache log file if HTTP error code is 500 (9th field logs status error code for each http request):
awk '$9 == 500 { print $0}' /var/log/httpd/access.log
The part outside the curly braces is called the „pattern“, and the part inside is the „action“. The comparison operators include the ones from C:
== != < > <= >= ?:
If no pattern is given, then the action applies to all lines. If no action is given, then the entire line is printed. If „print“ is used all by itself, the entire line is printed. Thus, the following are equivalent:
awk '$9 == 500 ' /var/log/httpd/access.log awk '$9 == 500 {print} ' /var/log/httpd/access.log awk '$9 == 500 {print $0} ' /var/log/httpd/access.log
setxkbdmap
user@host:~$ setxkbmap -print xkb_keymap { xkb_keycodes { include "evdev+aliases(qwertz)" }; xkb_types { include "complete" }; xkb_compat { include "complete" }; xkb_symbols { include "pc+de+inet(evdev)+terminate(ctrl_alt_bksp)" }; xkb_geometry { include "pc(pc105)" }; }; user@host:~$ setxkbmap -query rules: evdev model: pc105 layout: de options: terminate:ctrl_alt_bksp
On Apple MACs
Kleine Skripte und Abläufe unter Mac OSX
dd unter OS X
aus: DeGrimmis Blog - Link Eine Blog über meine Hobbies, Dinge die mich interessieren und ein paar Bilder Mit dem Befehl dd werden Daten aus einer Imagedatei auf einen Datenträger (SD-Karte, USB-Stick) kopiert. Der normale Befehl
sudo dd if=/path/to/source.img of=/dev/diskX bs=1m
führt meist zur Fehlermeldung „Device Busy“. Auf dem Mac reicht es nicht, den Zieldatenträger im Finder auszuwerfen. Es funktioniert nur, wenn im Terminal vorher der Befehl
sudo diskutil umountDisk /dev/diskX
ausgeführt wurde.
Nach dem Start von dd beginnt dann das große Warten. Leider gibt es standardmäßig keine Fortschrittsanzeige. Bei sehr großen Image-Dateien nervt das […]
Eine einfache Lösung ist, ein zweites Terminal zu öffnen oder mit CMD-T einen zusätzlichen Tab im Terminalfenster aufzumachen. Mit
ps a
sucht man such dann die PID von dd heraus und lässt sich mit
sudo kill -SIGINFO [PID]
den aktuellen Status anzeigen. Wem das zuviel Arbeit ist, der kann diese „Komplettlösung“ verwenden:
$ sudo -s # diskutil umountDisk /dev/diskX # dd if=Quellimage.img of=/dev/diskX bs=1m & pid=$! # while true; do clear; kill -SIGINFO $pid; sleep 10; done