awk examples

The Basics

An awk script usually takes the form

awk ‘pattern { action }’ file

where both pattern and action are optional. If there is no pattern, the action is performed on all lines. If there is action, the default action is to print all matching lines. Awk scripts are placed within single quotes when run in the command line to prevent the shell from interpreting it. Long awk scripts can be placed in a file and run as

awk -f the_script input_file

We can pass multiples to awk as well.

awk ‘pattern { action }’ file1 file2 file3

Examples:

Print all lines in a file(cat file)
awk ‘{print $0}’ file
awk ‘{print}’ file
awk ‘1’ file
Continue reading

Advertisements

Quick guide to tmux

I resisted tmux for a long time until today because screen has everything I need and I was afraid of having to remember more key strokes and commands. I gave tmux a try today and I think I am going to like it.

Start new tmux session
tmux new

Exit session. This will end the session
exit

Detach from the session. The session will keep running
^b d

Hit ^b, release and then hit d)

List existing tmux sessions
tmux ls

Attach a session
tmux attach-session -t
tmux a -t
Continue reading