Compare commits

..
2 Commits
2 changed files with 44 additions and 1 deletions
+2 -1
View File
@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
_1886 TILs and counting..._
_1887 TILs and counting..._
See some of the other learning resources I work on:
@@ -1873,6 +1873,7 @@ If you've learned something here, support my efforts writing daily TILs by
- [Make Neovim The Default Way To View Man Pages](unix/make-neovim-the-default-way-to-view-man-pages.md)
- [Manually Pass Two Git Files To Delta](unix/manually-pass-two-git-files-to-delta.md)
- [Map A Domain To localhost](unix/map-a-domain-to-localhost.md)
- [Merge A Sequence Of Lines Of Output](unix/merge-a-sequence-of-lines-of-output.md)
- [Move A List Of Files To Another Directory](unix/move-a-list-of-files-to-another-directory.md)
- [Negative Look-Ahead Search With ripgrep](unix/negative-look-ahead-search-with-ripgrep.md)
- [Occupy A Local Port With Netcat](unix/occupy-a-local-port-with-netcat.md)
@@ -0,0 +1,42 @@
# Merge A Sequence Of Lines Of Output
More often than not when I'm chaining a sequence of Unix commands together, I'm
eventually trying to fan them out or execute each argument separately. I
recently had the need for a bunch of separate lines of output to be fanned back
in to a single line.
The tool I found for this job is `paste` (not the most intuitive name).
> merge corresponding or subsequent lines of files
I was listing out all the categories that my active [TIL posts](https://github.com/jbranchaud/til) full under. I used the following
command to do that.
```bash
❯ git ls-files '*/*.md' | cut -d/ -f1 | sort -u
ack
ansible
astro
aws
bash
brew
chrome
...
```
Those are all my categories, but then the format I really wanted was for them to
be all on the same line with a clear delimiter so that I could paste them for
[use in another script](/llm/translate-to-canonical-tags-with-small-model.md).
The trick is to tack on one more pipe to `paste`. The `-s` tells `paste` to join
every line from a given input file (e.g. stdin) onto a single line. The `-d`
allows for overriding the default delimiter (tab) with something like a `,`.
Lastly, the trailing `-` tells `paste` to read from stdin rather than some other
named file(s).
```bash
❯ git ls-files '*/*.md' | cut -d/ -f1 | sort -u | paste -sd, -
ack,ansible,astro,aws,bash,brew,chrome,claude-code,clojure,css,cursor,deno,devops,docker,drizzle,elixir,gatsby,git,github,github-actions,go,groq,heroku,html,http,inngest,internet,java,javascript,jj,jq,kitty,linux,llm,mac,math,mise,mongodb,mysql,neovim,netlify,next-auth,nextjs,phoenix,planetscale,pnpm,postgres,prisma,python,rails,react,react_native,react-testing-library,reason,remix,rspec,ruby,sed,shell,sqlite,streaming,tailwind,taskfile,tmux,typescript,unix,vercel,vim,vscode,webpack,workflow,xstate,yaml,zed,zod,zsh
```
See `man paste` for more details.