From 1a81ad54a90e6bf1f434fd8d08bf4346c6f85010 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Fri, 6 Sep 2024 08:45:29 +0200 Subject: [PATCH] chore(kb/comm): add real-world example --- knowledge base/comm.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/knowledge base/comm.md b/knowledge base/comm.md index 9e0d314..8be5b53 100644 --- a/knowledge base/comm.md +++ b/knowledge base/comm.md @@ -10,14 +10,15 @@ With no options, produces 3 columns in output: Comparisons honor the rules specified by 'LC_COLLATE'. -## Table of contents - 1. [TL;DR](#tldr) 1. [Further readings](#further-readings) 1. [Sources](#sources) ## TL;DR +
+ Usage + ```sh # Print only lines present in both file1 and file2. comm -12 'path/to/pre-sorted/file1' 'path/to/pre-sorted/file2' @@ -31,6 +32,23 @@ test $(comm -23 'path/to/pre-sorted/file1' <(sort -u 'path/to/file2') | wc -l) - [[ $(comm -23 <(sort -u 'path/to/file1') 'path/to/pre-sorted/file2' | wc -l) -eq 0 ]] ``` +
+ +
+ Real world use cases + +```sh +# List security groups not used by EC2 instances in AWS. +comm -23 \ + <( aws ec2 describe-security-groups --query 'SecurityGroups[*].GroupId' --output 'text' | tr '\t' '\n' | sort ) \ + <( \ + aws ec2 describe-instances --query 'Reservations[*].Instances[*].SecurityGroups[*].GroupId' --output 'text' \ + | tr '\t' '\n' | sort | uniq \ + ) +``` + +
+ ## Further readings - [`cmp`][cmp] @@ -44,7 +62,8 @@ All the references in the [further readings] section, plus the following: - [6 more terminal commands you should know]