Skip to content

Space or Spaces as delimiter #1

@bradparks

Description

@bradparks

Hey! I tried this out and it works, so super nice... thanks!

For me to get it to work in lots of cases though, I find I have to do the following:

  • Convert a single space or multiple spaces to a tab or comma (if multiple spaces is the delimiter)

I also found that I had to skip lines at the start of my input, so I just did tail -n +2, but maybe that's something to consider as an option too...

I have a script that I use to convert multiple spaces to a single delimiter, but thought it might be good to support this as an option right in this tool. Here's what I use, for what it's worth

compress_spaces.sh

function show_help()
{
  IT=$(CAT <<EOF
  
  usage: {REPLACE_WITH}
  
  NOTE: If you pass in TAB, then multiple spaces are replaced with a TAB character

  no args -> multiple spaces replaced with a single space
  TAB     -> multiple spaces replaced with a single tab character
  TEST    -> multiple spaces replaced with the phrase "TEST"
  
  )
  echo "$IT"
  exit
}

if [ "$1" == "help" ]
then
  show_help
fi

# Show help if we're not getting data from stdin
if [ -t 0 ]; then
  show_help
fi

REPLACE_WITH=${1:-' '}

if [ "$REPLACE_WITH" == "tab" ]
then
  REPLACE_WITH=$'\t'
fi
if [ "$REPLACE_WITH" == "TAB" ]
then
  REPLACE_WITH=$'\t'
fi

sed "s/ \{1,\}/$REPLACE_WITH/gp"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions