1-liner to get latest version in a changelog file
Heres the one-liner in a code block:
cat debian/changelog | awk '{print $2;}' | sed 1q | tr -d '()' | cut -d - -f 1
This code is used to extract a piece of information (the version number of a Debian package) from a well-structured text (the Debian changelog file).
Lets explain each step and observe transformation of partial output:
cat debian/changelog: This command is used to view the content of the debian/changelog file.
json-toolkit (1.2.0-4) focal; urgency=medium
...
awk '{print $2;}': AWK is a programming language that is designed for text processing. This portion of the one-liner attempts to print out the second field (the fields are divided by whitespaces by default) of every line of debian/changelog. Characters inside the parentheses are considered one field.
(1.2.0-4)
...
sed 1q: SED is a stream editor. It can perform lots of functions on files like, searching, find and replace, insertion/deletion. Here, its used to quit(print and then quit) after the first line.
(1.2.0-4)
tr -d '()': TR is a command-line utility for translating or deleting characters. This portion of the one-liner is used to delete the parentheses.
1.2.0-4
cut -d - -f 1: The cut is a command-line utility for cutting sections from each line of files. This piece of code is used to cut the string into pieces by - and then print out the first piece.
1.2.0
In conclusion, this one-liner reads the debian/changelog file, and then retrieves and formats the version number of the latest package.