fork download
  1. #!/bin/bash
  2.  
  3. # ideone boilerplate: run in temp dir
  4. t=$(mktemp -d -t ideone.XXXXXXXX) || exit
  5. trap 'rm -rf "$t"' ERR EXIT
  6. cd "$t"
  7.  
  8. printf '%s\0' \
  9. b s n \
  10. a d q \
  11. a x w \
  12. aa y not \
  13. c p f \
  14. a z m >file
  15.  
  16. cat <<\: >prog.py
  17. import sys
  18.  
  19. with open(sys.argv[1], 'rb') as fh:
  20. seq = fh.read().split(b'\x00')
  21. items = [b'\x00'.join(seq[i:i + 3]) for i in range(0, len(seq)-1, 3)]
  22. print(b'\x00'.join(sorted(items)).decode('us-ascii'))
  23. :
  24.  
  25. python3 prog.py file | xxd
  26.  
  27. perl -0 -ne 'push @rec, $_;
  28. if ($#rec == 2) { push @items, join("", @rec); @rec = (); }
  29. END { print(join("", sort @items)) }' file |
  30. xxd
  31.  
  32.  
Success #stdin #stdout 0.04s 9148KB
stdin
Standard input is empty
stdout
00000000: 6100 6400 7100 6100 7800 7700 6100 7a00  a.d.q.a.x.w.a.z.
00000010: 6d00 6161 0079 006e 6f74 0062 0073 006e  m.aa.y.not.b.s.n
00000020: 0063 0070 0066 0a                        .c.p.f.
00000000: 6100 6400 7100 6100 7800 7700 6100 7a00  a.d.q.a.x.w.a.z.
00000010: 6d00 6161 0079 006e 6f74 0062 0073 006e  m.aa.y.not.b.s.n
00000020: 0063 0070 0066 00                        .c.p.f.