Tag Archives: bash

linux bash arrays

cat domains.txt
google.com
domains.com
gmail.com
yahoo.com
#!/bin/bash
DOMAINS=`cat domains.txt`
HTTP1=""
for domain in $DOMAINS ; do
    code=`curl -I $domain 2>/dev/null | grep HTTP | awk '{print $2}'`
    if [ ! -z $HTTP1 ];then
       HTTP1+="|"
    fi
    HTTP1+="$domain:$code"
done
echo $HTTP1
IFS='|'
readarray -d '|' ARR <<< $HTTP1
#
arraylength=${#ARR[@]}
for (( i=1; i<${arraylength}+1; i++ ));
do
  echo $i ${ARR[$i-1]}
done

Linux sed

Delete ESC sequences from file

sed  -i "s/\x1B\[[0-9;]*[a-zA-Z]//g" 

Insert line at the beginning of the file

sed -i '1 iNew string value' /path/to/file

Replace /home10/incorrect_path by /home10/correct_path at line that start from Value1 in file /etc/proftpd/user2

sed -ei '/^Value1/ s|/home10/incorrect_path|/home10/correct_path|' /etc/proftpd/user2