Filtering Examples
This page shows practical examples of using grph CLI's filtering capabilities to find specific nodes and edges in your graphs.
Node Filtering
By Single Attribute
Find all nodes of a specific type:
grph nodes network.gexf --attr type=server
By Multiple Attributes (AND)
Find servers with a specific weight:
grph nodes network.gexf --attr type=server --attr weight=2.0
Both conditions must be true for a node to match.
By Label Pattern
Find nodes with labels starting with "Web":
grph nodes network.gexf --label "Web*"
Find nodes with labels containing "Server":
grph nodes network.gexf --label "*Server*"
Find nodes with labels matching a pattern:
grph nodes network.gexf --label "Server[12]" # Matches Server1 or Server2
Combine Attribute and Label Filters
Find servers with labels starting with "Production":
grph nodes network.gexf --attr type=server --label "Production*"
Edge Filtering
By Source Node
Find all edges originating from a specific node:
grph edges network.gexf --source loadbalancer1
By Target Node
Find all edges pointing to a specific node:
grph edges network.gexf --target database1
By Both Source and Target
Check if there's a direct connection between two nodes:
grph edges network.gexf --source server1 --target database1
By Attribute
Find edges with a specific relationship:
grph edges network.gexf --attr relationship=queries
Complex Edge Queries
Find all query edges from server1:
grph edges network.gexf --source server1 --attr relationship=queries
Find heavy-weight edges to the database:
grph edges network.gexf --target database1 --attr weight=2.0
Real-World Scenarios
Infrastructure Analysis
Find all database connections:
grph edges infra.gexf --attr relationship=queries
Find all nodes in a specific tier:
grph nodes infra.gexf --attr tier=frontend
Find all connections to a specific service:
grph edges infra.gexf --target api-gateway
Social Network Analysis
Find all users in a community:
grph nodes social.gexf --attr community=tech
Find all connections of a specific type:
grph edges social.gexf --attr type=follows
Find connections from a specific user:
grph edges social.gexf --source user123
Dependency Analysis
Find all direct dependencies of a package:
grph edges deps.gexf --source my-package
Find all packages that depend on a library:
grph edges deps.gexf --target lodash
Find dev dependencies:
grph edges deps.gexf --attr scope=dev
Tips
No Results?
If your filter returns no results:
-
Check available attributes with
grph info:grph info graph.gexf -
List all nodes/edges first to see what values exist:
grph nodes graph.gexf
grph edges graph.gexf -
Attribute matching is case-sensitive and exact:
--attr type=Serverwon't matchtype=server--attr weight=1won't matchweight=1.0
Checking Specific Values
Use JSON output with jq to explore unique values:
# Find all unique node types
grph nodes graph.gexf --json | jq '[.[].attributes.type] | unique'
# Find all unique edge relationships
grph edges graph.gexf --json | jq '[.[].attributes.relationship] | unique'
Complex Filtering with jq
For queries that grph CLI doesn't support directly (like numeric comparisons or OR logic), use JSON output with jq:
# Nodes with weight > 1.0
grph nodes graph.gexf --json | jq '[.[] | select(.attributes.weight > 1.0)]'
# Edges with weight between 1.0 and 2.0
grph edges graph.gexf --json | jq '[.[] | select(.weight >= 1.0 and .weight <= 2.0)]'
# Nodes of type "server" OR "database"
grph nodes graph.gexf --json | jq '[.[] | select(.attributes.type == "server" or .attributes.type == "database")]'