# Category Archives: Uncategorized

## Nl

Add line numbers to a file (Four digits, leading zeros, separated by a colon): nl -i1 -s’: ‘ -nrz -w4 cotus.txt awk ‘{printf”%04d: “,NR;print}’ cotus.txt Oh wait, you don’t want to count the blank lines? awk ‘/[^ ]/{printf”%04d: “,++n}{print}’ cotus.txt … Continue reading

## Fgrep

Print line numbers of matches with #fgrep fgrep -n Revenue cotus.txt

## Djpeg

Convert a JPG to a 4-bit per pixel BMP: djpeg -colors 16 teresita.jpg > teresita16.bmp

## Absolute

Calculate absolute magnitude from visual magnitude for Sirius and Tau Ceti #!/usr/bin/python3 import math vmag = float(input(“Visual magnitude?: “)) dist = float(input(“Distance in light-years?: “)) amag = vmag-5*((math.log(dist/3.26156)/math.log(10))-1) print (“Absolute magnitude=”,amag)

## LaTex

Okay, here’s a way ChatGPT can shine, teaching LaTeX : R_{\mu\nu} – \frac{1}{2} g_{\mu\nu} R + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu}

## Contour

Plot a function as a contour map #!/usr/bin/python3 import matplotlib.pyplot as plt import numpy as np X, Y = np.meshgrid(np.linspace(-4, 4, 512), np.linspace(-4, 4, 512)) Z = (1 – X/2 + X**4 + Y**3) * np.exp(-X**2 – Y**2) * (1 … Continue reading

## Wash

Plot city population as a pie chart for Washington cities with more than 100,000 people #!/usr/bin/python3 import matplotlib.pyplot as plt labels = ‘Seattle’, ‘Spokane’, ‘Tacoma’, ‘Vancouver’, ‘Bellevue’,’Kent’, ‘Everett’, ‘Renton’, ‘Spokane Valley’, ‘Federal Way’ sizes = [737015, 228989, 219346, 190915, 151854, … Continue reading

## Grep

Use grep to find adjacent duplicate words in standard input: nl gettysburg.txt | grep -E “(\b\w+\b)\s+\1”