Skip to content

Instantly share code, notes, and snippets.

@fabiolimace
Last active April 5, 2025 22:10
Show Gist options
  • Save fabiolimace/7bc48d3b3c91a7509c746e119a89fd61 to your computer and use it in GitHub Desktop.
Save fabiolimace/7bc48d3b3c91a7509c746e119a89fd61 to your computer and use it in GitHub Desktop.
Search records in a Cookie-Jar format file. Moved to https://github.com/fabiolimace/awk-tools
%% Mercury
Planet: Mercury
Orbital-Radius: 57,910,000 km
Diameter: 4,880 km
Eccentricity: 0.2
Mass: 3.30e23 kg
%% Venus
Planet: Venus
Orbital-Radius: 108,200,000 km
Diameter: 12,103.6 km
Eccentricity: 0.007
Mass: 4.869e24 kg
%% Earth
Planet: Earth
Orbital-Radius: 149,600,000 km
Diameter: 12,756.3 km
Eccentricity: 0.0167
Mass: 5.972e24 kg
Moons: Luna
%% Jupiter
Planet: Jupiter
Orbital-Radius: 778,000,000 km
Diameter: 142,984 km
Eccentricity: 0.0489
Mass: 1.8982e27 kg
Moons: Callisto
Moons: Europa
Moons: Io
Moons: Ganymede
@fabiolimace
Copy link
Author

Examples:

# show the records whose keys contain "Earth"
./cookie-jar-search-by-key.awk -v KEY=Earth planets.txt
%% Earth
Planet: Earth
Orbital-Radius: 149,600,000 km
Diameter: 12,756.3 km
Eccentricity: 0.0167
Mass: 5.972e24 kg
Moons: Luna
# show the records whose contents contain "Moon"
./cookie-jar-search-by-value.awk -v VALUE=Moon planets.txt
%% Earth
Planet: Earth
Orbital-Radius: 149,600,000 km
Diameter: 12,756.3 km
Eccentricity: 0.0167
Mass: 5.972e24 kg
Moons: Luna
%% Jupiter
Planet: Jupiter
Orbital-Radius: 778,000,000 km
Diameter: 142,984 km
Eccentricity: 0.0489
Mass: 1.8982e27 kg 
Moons: Callisto
Moons: Europa
Moons: Io
Moons: Ganymede

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment