Shell

This is a common task for every administrator. We have a large file with many empty lines. We want to remove them.

$ cat ./file.txt
Line 1

Line 2
Line 3
Line 4

Line 5
Line 6

Line 7
Line 8
Line 9

Line 10

This command removes all empty lines or those that contain only whitespace characters.

$ sed '/^\s*$/d' ./file.txt 
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10

Simple and useful!

Sometimes we need limit the access to some system resources or files. We want to be sure that the only one process to have an access to them in the same time. This short article explains how to use exclusive locks in shell scripts.

Assume we have a shell script (‘writer.sh‘) which writes an output file (‘output.txt‘). It writes the file line by line with one second delay between each line.

Continue Reading