Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

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=$'	'
fi
if [ "$REPLACE_WITH" == "TAB" ]
then
  REPLACE_WITH=$'	'
fi

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

PREVIOUS NEXT
Code Example
Shell :: rename tool numeric linux 
Shell :: proxy v git 
Shell :: sudo add-apt-repository ppa:diodon-team/stable 
Shell :: cmd for statement 
Shell :: Git Kraken update Linux 
Shell :: node_modules spotlight index 
Shell :: install homebrew on godaddy 
Shell :: select adb device to install apk 
Shell :: bashrc setup "android" example 
Shell :: mac run a shell script 
Shell :: install slurm ubuntu 20.04 
Shell :: shell access 
Shell :: what is 127 of echo $? 
Shell :: unpause jobs bash 
Shell :: linux find follow symlinks 
Shell :: get or filter or ouput docker ps custom columns 
Shell :: install openzeppelin 
Shell :: Unset a Variable; Remove Variable; Delete Variable 
Shell :: We need to generate a lot of random bytes. It is a good idea to perform some other action 
Shell :: debian change owner 
Shell :: easter egg bash 
Shell :: vue search npm 
Shell :: git lg config 
Shell :: install gui apps using homebrew 
Shell :: bash for loop with decimals 
Shell :: auto git script 
Shell :: error: home_manuelschneid3r_Arch: key "" is unknown 
Shell :: BertinAm github 
Shell :: chmod root to user 
Shell :: docker compose logs container stdout 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =