Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space or Spaces as delimiter #1

Open
bradparks opened this issue Nov 1, 2016 · 1 comment
Open

Space or Spaces as delimiter #1

bradparks opened this issue Nov 1, 2016 · 1 comment

Comments

@bradparks
Copy link

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"
@Reflexe
Copy link
Owner

Reflexe commented Nov 2, 2016

First of all, thanks for the feedback :)

I have added support for multiple delimiters and delimiters repeat count, now it is much smarter than before (see the new readme).

@Reflexe Reflexe closed this as completed Nov 2, 2016
@Reflexe Reflexe reopened this Nov 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants