Stop writing massive temp files just to sort your arrays

Shell Scripting / Bash Tricks

Stop writing massive temp files just to sort your arrays

🧩 The Challenge

Dealing with a massive list of server hostnames or IDs and trying to get a clean, sorted unique set usually ends up with me creating ugly temp files I always forget to delete. It’s a mess and it makes the filesystem look like a graveyard of abandoned text files.

💡 The Fix

Bash has process substitution which lets you treat the output of commands as files without ever actually touching the disk. You can feed multiple command outputs directly into sort as if they were real files on the path.

comm -12 <(sort file1.txt) <(sort file2.txt) | uniq

⚙️ Why It Works

Using the <(…) syntax forces the shell to run the command in the parentheses and connect the output to a named pipe, which looks just like a regular file to the downstream utility. It cleans up your scripts immediately because you aren’t leaving junk files in /tmp anymore.

🚀 Pro-Tip: Use this with diff as well if you need to compare live config outputs without saving them to disk first.

Linux Tips & Tricks | © ngelinux.com | 10/29/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted