{
  "$type": "site.standard.document",
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreieehsdjufgnt5zvf4kxa6epwcf7khbcyxkdkokrnu55p2eh774xxe"
    },
    "mimeType": "image/jpeg",
    "size": 2453
  },
  "path": "/link/535/17260953/tween-fish-function-for-outputting-ranges-of-text",
  "publishedAt": "2026-01-22T16:51:00.000Z",
  "site": "https://brett.trpstra.net",
  "tags": [
    "Fish functions repository",
    "tween.fish",
    "on Mastodon",
    "Bluesky",
    "Twitter",
    "Click here if you'd like to help out.",
    "Mastodon",
    "Bluesky",
    "GitHub",
    "everywhere else"
  ],
  "textContent": "I’ve been developing a Fish function called `tween`. It’s a simple, flexible utility for extracting ranges of lines from files or STDIN input, and it’s flexible enough to handle just about any scenario you can throw at it, from numeric ranges, array style position/length ranges, or even string matching with regex capabilities.\n\nYou can find the source code in my Fish functions repository, specifically at tween.fish.\n\n## What it does\n\n`tween` displays lines between a start and end point. The start and end can be line numbers, string matches, or regex patterns. It supports multiple ranges, relative offsets, and even works with piped input.\n\n## Basic usage\n\nThe simplest form is specifying line numbers:\n\n\n    tween file.txt 10 20\n\nThis displays lines 10 through 20 (inclusive). You can also use a dashed range format:\n\n\n    tween file.txt 10-20\n\nAnd here’s the nice part: arguments can be in any order. Both of these work the same way:\n\n\n    tween file.txt 10 20 tween 10 20 file.txt\n\nIf you only specify a single line number, `tween` will display from that line to the end of the file:\n\n\n    tween file.txt 50\n\nThis shows lines 50 through the end of the file.\n\n## Multiple ranges\n\nNeed to extract several sections? Just separate them with commas:\n\n\n    tween file.txt 10-20,30-40 tween file.txt 10 20, 30 40\n\nBoth formats work, so use whichever feels more natural.\n\n## Relative offsets\n\nSometimes you know where you want to start but need to go a certain number of lines forward. Use `+N` for relative offsets:\n\n\n    tween file.txt 10 +20\n\nThis displays lines 10 through 30 (10 plus 20 lines). You can also count from the end using `-N`:\n\n\n    tween file.txt 50 -10\n\nThis shows lines 50 to 10 lines from the end of the file. There’s a special case: `-1` means the end of the file (the last line):\n\n\n    tween file.txt 50 -1\n\nThis displays lines 50 through the end of the file. Other negative numbers like `-2`, `-3`, etc. still mean “N lines from the end” (second-to-last, third-to-last, etc.).\n\n## String matching\n\nInstead of line numbers, you can match on strings. This is super useful when you know the content but not the exact line:\n\n\n    tween file.txt 'START' +20\n\nThis finds the line containing “START” and displays it plus the next 20 lines. You can also use string matching for both start and end:\n\n\n    tween file.txt 50-'END'\n\nThis shows lines 50 through the line containing “END”.\n\n## Regex patterns\n\nFor more complex matching, use regex patterns wrapped in slashes:\n\n\n    tween file.txt /START/ +20\n\nThis matches the regex pattern “START” and displays that line plus 20 more. You can also use the `-r` or `--regex` flag to treat all string arguments as regex:\n\n\n    tween -r file.txt 'foo' 'bar'\n\nBoth patterns are treated as regex when using the `-r` flag.\n\n## Exclusive mode\n\nSometimes you want the lines _between_ two markers but not the markers themselves. Use `-e` or `--exclusive`:\n\n\n    tween -e file.txt 'BEGIN' 'END'\n\nThis displays all lines between (but not including) the lines containing “BEGIN” and “END”.\n\n## Syntax highlighting with bat\n\nIf you have `bat` installed, you can use it for syntax highlighting with the `-b` or `--bat` flag:\n\n\n    tween -b file.txt 10-20\n\nThis displays the range with syntax highlighting, which is especially nice when viewing code.\n\n## Piped input\n\n`tween` works with piped input too. Just use `-` as the file argument:\n\n\n    cat file.txt | tween 10-20,30-40 -\n\nThis is handy when you’re already working with a pipeline.\n\n## Options summary\n\n  * `-e, --exclusive` - Exclude the start and end lines from output\n  * `-b, --bat` - Use bat instead of sed for syntax highlighting\n  * `-r, --regex` - Treat all string arguments as regular expressions\n  * `-h, --help` - Show help message\n\n\n\nThe function is flexible enough to handle most text extraction tasks, and the ability to mix line numbers, strings, and regex makes it incredibly versatile. Give it a try and see how it fits into your workflow!\n\nLike or share this post on Mastodon, Bluesky, or Twitter.\n\n* * *\n\nBrettTerpstra.com is supported by readers like you. Click here if you'd like to help out.\n\nFind Brett on Mastodon, Bluesky, GitHub, and everywhere else.",
  "title": "Tween: Fish function for outputting ranges of text",
  "updatedAt": "2026-01-22T16:51:00.000Z"
}