Skip to content

Instantly share code, notes, and snippets.

@ben-ng
Created March 4, 2019 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-ng/958e1d4b559be7a32a33e06355511ed7 to your computer and use it in GitHub Desktop.
Save ben-ng/958e1d4b559be7a32a33e06355511ed7 to your computer and use it in GitHub Desktop.
Solution for reversing a linked list in bash
#!/usr/bin/env bash
# Where input.txt is:
# a>b
# b>c
# c>d
# d>e
paste -d '>' <(< input.txt | cut -d'>' -f2 | tac) <(< input.txt | cut -d'>' -f1 | tac)
# Output:
# e>d
# d>c
# c>b
# b>a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment