Selecting and Filtering Rows
Row selection in VisiData is the foundation of all bulk operations: delete, export, aggregate, and filter. Selected rows appear highlighted in yellow and serve as the target for g-prefixed commands.
Learning Focus
Master the four selection methods — single row, regex, Python expression, and value match — and the workflow of selecting rows then opening a filtered sheet with ".
Basic Row Selection
| Key | Action |
|---|---|
s | Select current row |
u | Unselect current row |
t | Toggle selection of current row |
gs | Select all rows |
gu | Unselect all rows |
gt | Toggle selection of all rows |
{ | Jump to previous selected row |
} | Jump to next selected row |
Select by Regex
| regex select rows where current column matches regex
\ regex unselect rows where current column matches regex
g| regex select rows where ANY visible column matches regex
g\ regex unselect rows where ANY visible column matches regex
Example:
# Move cursor to 'status' column
|
# Enter: active
# All rows with 'active' in status column are selected (yellow)
Select by Python Expression
z| expr select rows matching Python expression in current column
z\ expr unselect rows matching Python expression
Example:
# Select all rows where salary > 50000
z|
# Enter: salary > 50000
# Select rows where hostname starts with 'web'
z|
# Enter: hostname.startswith('web')
Select by Matching Value
, (comma) select rows matching display value of current cell in current column
g, select rows matching display value of current row in all visible columns
z, select rows matching typed value of current cell in current column
Example:
# Move cursor to a cell containing 'Singapore'
,
# All rows where the same column = 'Singapore' are selected
Open a Filtered Sheet
After selecting rows, press " to open a new sheet containing only the selected rows:
" open new sheet with only selected rows
g" open new sheet with ALL rows (unfiltered copy)
gz" open new sheet with deep copy of selected rows
This creates a non-destructive derived sheet — the source is unchanged.
Sorting Rows
[ sort ascending by current column
] sort descending by current column
g[ sort ascending by all key columns
g] sort descending by all key columns
z[ sort ascending — keep higher priority sort criteria
z] sort descending — keep higher priority sort criteria
info
Sorting is done in-place on the current sheet. To preserve the original order, open a copy with g" first.
Practical Use Cases
Export Active Servers to CSV
vd /tmp/servers.csv
# Move to 'status' column
# Select active rows
|
# Enter: active
# Open filtered sheet
"
# Save filtered result
Ctrl+S
# Enter: /tmp/active_servers.csv
Find and Delete Error Rows
vd /tmp/data.csv
# Select all rows where 'status' contains 'error'
|
# Enter: error
# Delete selected rows
gd
# (prompts for confirmation if quitguard is on)
# Save cleaned file
Ctrl+S
# Enter: cleaned_data.csv
Filter High-Value Orders
vd /var/www/html/exports/orders.csv
# First, cast 'amount' to float: move cursor to column, press %
# Then select high-value rows
z|
# Enter: amount > 1000
# Open filtered sheet for export
"
Ctrl+S
# Enter: /tmp/high_value_orders.csv
Troubleshooting Matrix
| Problem | Cause | Fix |
|---|---|---|
| ` | ` selects no rows | Regex is wrong |
| `z | ` throws error | Column not typed correctly |
, selects wrong rows | Cell display value vs stored value | Use z, for typed value match |
" creates empty sheet | No rows selected | Press s or gs first |
Best Practices
- Always verify your selection count (shown in status bar) before running bulk operations like
gd(delete). - Use
z|with Python expressions for complex business logic filtering that regex cannot express. - Use
"to create a working copy before destructive edits — the source is always preserved.
Hands-On Practice
cat > /tmp/servers.csv << 'EOF'
hostname,role,status,region
web01,webserver,active,sg
web02,webserver,standby,sg
db01,database,active,kl
cache01,cache,active,sg
monitor01,monitoring,standby,jk
EOF
vd /tmp/servers.csv
# 1. Move to 'status' column, press | and type: active
# 2. Count selected rows in status bar
# 3. Press " to open filtered sheet
# 4. Press Ctrl+S → save as /tmp/active.csv
# 5. Press q → return to source
# 6. Press gu → deselect all