Tags » Shell Script

read multiple files on loop bash

while read line; do 
  echo $line; 
done < <( paste /etc/hosts /etc/passwd )
Shell Script

sed command usage

Command sed means “Stream EDitor”. The format for searching and replacing is as below:

sed -i.bak s/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g build.gradle

Explanation: pass the -i  option to sed to make the changes inline and create a backup of the original file before it does the changes in-place. 218 more words

Shell Script

generates a list of users and groups on linux

generates a list of all users with command to create them in another machine

cut -d: --output-delimiter=' ' -f1,3,4 /etc/passwd | sort -k2n | xargs -n3 sh -c 'echo useradd -u $1 -g $2 $0'
… 33 more words
Shell Script

audible ping

using ping

while sleep 3;do ping -a -c 1 8.8.8.8; done

using beep

while sleep 3;do ping -c 1 8.8.8.8 && beep; done

using mplayer… 11 more words

Shell Script

creating columns bash

create 1 column

seq 10

create 2 columns

printf %s\\n ID-{1..3}' '{10..25..5}

create 3 or more columns

seq 12 | pr -3t | column -t
Shell Script

confirm action on bash

using only read

read -p 'Press any key to confirm or Ctrl-C to Cancel'
echo some key was pressed!

using echo and read

echo -e Press any key to "\e[32;1mconfirm\e[m" or Ctrl-C to Canncel
read
echo some key was pressed!
Shell Script