How to Left Pad Numbers in AWK

Occasionally when working in a Linux/Unix environment comes the need to left pad numbers with zeros (add leading zeros to numbers). This is often done to make a series of numbers the same length. An example of doing this with awk can be seen below:

Sorting JSON by Value with JQ (Command Line JSON Processor)

jq is a lightweight command line JSON processor that is very easy to use. Sometimes it is helpful to see your data sorted by a particular field value. Luckily jq makes this easy to do. Here are some sample JSON records we will be working with in this post:

Sorting JSON by value with

read more

Using Variables in JQ (Command Line JSON Parser)

jq is a lightweight command line JSON processor that is very easy to use. Sometimes being able to use variables within a jq script is very useful. Below are various examples of doing this. Here is a sample record from the JSON file we use in most examples:

Using Simple Variables in jq To

read more

How to filter JSON records by value with jq

Often when working with JSON in a Linux/Unix environment, it is nice to be able to filter records based on the values of certain fields. jq is a lightweight command line JSON processor that is very easy to use. jq offers an easy way to filter JSON records based on field values with the select()

read more

How to Left Pad Numbers in Linux

There are many ways to left pad numbers in Linux. Usually this seems to be done by adding leading zeros in front of the main number. A few examples of doing this can be seen below: Using printf

Using AWK

Looping in Bash

How to Pretty Print JSON on the Command Line

JSON is a very popular platform independent data format. One of the great benefits of working with JSON is that it is generally easy to read. However, reading JSON objects becomes more difficult as the objects become large, especially on the command line. Pretty printing JSON records on the command line makes reading it much

read more

Count Number of Occurrences of Characters in Line with AWK

Being able to count the number of occurrences of characters or words in text is a handy trick. Fortunately this is very easy to do in awk with the gsub() function. The syntax for using gsub() looks like this: gsub(regexp, replacement [, target]) gsub() will search target for substrings matching the provided regular expression and

read more

Select Random Lines from file in Linux

Being able to select random lines from a file in Linux can be very helpful and convenient. There are a few easy ways to do this, including using the shuf utilty. shuf is included on many Linux/Unix systems as part of GNU coreutils. GNU coreutils can be easily installed if not already. Selecting Random Lines

read more

How to Generate a UUID in Linux

UUID stands for Universally Unique Identifier. UUIDs are used as IDs (to identify) unique objects or records. An easy way to generate UUIDs in Linux is to use the uuidgen utility on the Linux/Unix command line. Generating UUID with uuidgen Simply executing uuidgen will generate a random UUID. Using the -t option will create a

read more

How to Copy local files to S3 with AWS CLI

AWS CLI has made working with S3 very easy. Once you get AWS CLI installed you might ask “How do I start copying local files to S3?” The syntax for copying files to/from S3 in AWS CLI is: aws s3 cp <source> <destination> The “source” and “destination” arguments can either be local paths or S3

read more