# String Operations Guide
Comprehensive guide to hawk's text processing capabilities.
## 📖 Table of Contents
- [Basic Operations](#basic-operations)
- [Advanced Operations](#advanced-operations)
- [Array Operations](#array-operations)
- [Multi-field Operations](#multi-field-operations)
- [Practical Examples](#practical-examples)
- [Performance Tips](#performance-tips)
## Basic Operations
### Case Conversion
```bash
# Convert to uppercase
# Convert to lowercase
# Example
```
### Whitespace Management
```bash
# Remove all whitespace
# Remove leading whitespace
# Remove trailing whitespace
# Examples
" hello " | trim_end → " hello"
```
### String Analysis
```bash
# Get string length
# Reverse strings
# Examples
```
## Advanced Operations
### Pattern Matching
```bash
# Check if string contains pattern
# Check string start/end
# Examples
"Hello World" | ends_with("World") → true
```
### Text Transformation
```bash
# Replace text
# Extract substrings
# Examples
"Hello World" | substring(6) → "World"
```
## Array Operations
### String Splitting
```bash
# Split into array
# Split with index access (NEW in v0.2.2!)
# Examples
"apple,banana,cherry" | split(",")[1] → "banana"
```
### Array Joining
```bash
# Join array elements
# Examples
```
## Multi-field Operations
Process multiple fields with the same operation (NEW in v0.2.2!):
```bash
# Apply join to multiple array fields
# Convert multiple fields to uppercase
# Get length of multiple string fields
### Example: User Data Processing
```json
{
"users": [
{
"name": "alice",
"skills": ["python", "rust"],
"projects": ["web-app", "cli-tool"],
"department": "engineering"
}
]
}
```
```bash
# Process multiple fields simultaneously
# Result
{
"users": [
{
"name": "ALICE", // ← converted
"skills": ["python", "rust"],
"projects": ["web-app", "cli-tool"],
"department": "ENGINEERING" // ← converted
}
]
}
```
## Practical Examples
### Log File Processing
```bash
# Extract timestamps from logs
# Find unique IP addresses
# Extract error messages
### Data Cleaning
```bash
# Normalize email addresses
# Clean phone numbers
# Standardize names
### CSV Processing
```bash
# Extract specific columns from CSV-like text
# Process headers and data separately
```
### Docker/Container Logs
```bash
# Extract container names
# Get timestamps and services
# Filter by service and extract messages
## Performance Tips
### Efficient Patterns
```bash
# ✅ Good: Filter first, then transform
# ❌ Avoid: Transform everything, then filter
### Memory Considerations
```bash
# ✅ Process in chunks for large files
# ✅ Use specific operations instead of general ones
### Text Format Detection
```bash
# ✅ Use --text flag for ambiguous files
# ✅ Especially important for logs that might be detected as YAML
## Error Handling
### Common Issues
```bash
# Array index out of bounds → returns empty string
# Missing fields → error (use select to filter first)
### Debugging Tips
```bash
# Check data structure first
# Test operations step by step
```
## Chaining Operations
### Pipeline Examples
```bash
# Complex text processing pipeline
# Multi-step data cleaning
# Log analysis workflow
---
**Next Steps:**
- [Data Analysis Guide](data-analysis.md) - Statistical operations and aggregation
- [Log Analysis Examples](examples/log-analysis.md) - Real-world log processing
- [Query Language Reference](query-language.md) - Complete syntax guide