Horje
remove white space from file and display result Code Example
remove white space from file and display result
#!/usr/bin/env bash

function show_help()
{
  ME=$(basename "$0")
  IT=$(cat <<EOF

  usage: $ME {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"

  $ME 
EOF
)
  echo "$IT"
  echo
  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"




Shell

Related
Git blame get users most edited file Code Example Git blame get users most edited file Code Example
install ntfs support debian Code Example install ntfs support debian Code Example
create new workflow branch Code Example create new workflow branch Code Example
debian bullseye install nvm Code Example debian bullseye install nvm Code Example
upstream revert merge Code Example upstream revert merge Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
12