title: unix - cut command (adding own delimiter)
body: <p>Given a file with data like this (ie stores.dat file)</p>
  
  <pre><code>id               storeNo     type
  2ttfgdhdfgh      1gfdkl-28   kgdl
  9dhfdhfdfh       2t-33gdm    dgjkfndkgf
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>id               |storeNo     |type
  2ttfgdhdfgh      |1gfdkl-28   |kgdl
  9dhfdhfdfh       |2t-33gdm    |dgjkfndkgf
  </code></pre>
  
  <p>Would like to add a "|" delimiter between each of these 3 cut ranges:</p>
  
  <pre><code>cut -c1-18,19-30,31-40 stores.dat
  </code></pre>
  
  <p>What is the syntax to insert a delimiter between each cut?</p>
  
  <p>BONUS pts (if you can provide the option to trim the values like so):</p>
  
  <pre><code>id|storeNo|type
  2ttfgdhdfgh|1gfdkl-28|kgdl
  9dhfdhfdfh|2t-33gdm|dgjkfndkgf\
  </code></pre>
  
  <p><strong>UPDATE (thanks to Mat's answer) I ended up with success on this solution - (it is a bit messy but SunOS with my bash version doesn't seem to support more elegant arithmetic)</strong></p>
  
  <pre><code>#!/bin/bash
  unpack=""
  filename="$1"
  while [ $# -gt 0 ] ; do
      arg="$1"
      if [ "$arg" != "$filename" ]
      then
          firstcharpos=`echo $arg | awk -F"-" '{print $1}'`
          secondcharpos=`echo $arg | awk -F"-" '{print $2}'`
          compute=`(expr $firstcharpos - $secondcharpos)`
          compute=`(expr $compute \* -1 + 1)`
          unpack=$unpack"A"$compute
      fi
      shift
  done
  perl -ne 'print join("|",unpack("'$unpack'", $_)), "\n";' $filename 
  </code></pre>
  
  <p>Usage: sh test.sh input_file 1-17 18-29 30-39 </p>