Home > front end >  shell script to create text using data
shell script to create text using data

Time:06-17

I have one file that contains data like this

User= yojpackco
Domains=yojpack.com


User= yugmaimpre
Domains=yugmaimpressions.com


User= yvmarathej
Domains=yvmarathejewellers.com


User= zawargauge
Domains=zawargauges.com


User= zealservi
Domains=zeal-services.com


User= zenithwor
Domains=zenith-worldwide.com

I want to create a txt like this using the first data where domains will replace actual URL and user will replace User FROM ABOVE

echo 'Sitemap: https://Domains/sitemap.xml' | tee -a /home/User/public_html/robots.txt >/dev/null

echo 'Sitemap: https://yojpack.com/sitemap.xml' | tee -a /home/yojpackco/public_html/robots.txt >/dev/null
echo 'Sitemap: https://yugmaimpressions.com/sitemap.xml' | tee -a /home/yugmaimpre/public_html/robots.txt >/dev/null
echo 'Sitemap: https://yvmarathejewellers.com/sitemap.xml' | tee -a /home/zawargauge/public_html/robots.txt >/dev/null
echo 'Sitemap: https://zawargauges.com/sitemap.xml' | tee -a /home/zealservi/public_html/robots.txt >/dev/null
echo 'Sitemap: https://zenith-worldwide.com/sitemap.xml' | tee -a /home/zenithwor/public_html/robots.txt >/dev/null

CodePudding user response:

Edit: Following CharlesDuffy's comment, I modified the code to make it a valid solution instead of an insecure example.

awk -F'\n' -v RS="" '
    {
        delete keys
        for ( n = 1; n <= NF; n   )
            if (match($n,/ *= */))
                keys[substr($n,1,RSTART-1)] = substr($n,RSTART RLENGTH)
        if ("Domains" in keys && "Users" in keys)
            print "Sitemap: https://"keys["Domains"]"/sitemap.xml" >> "/home/"keys["User"]"/public_html/robots.txt"
    }
' file

CodePudding user response:

#!/bin/bash

while read -r user domain; do 
  echo "Sitemap: https://${domain}/sitemap.xml" | tee -a /home/"${user}"/public_html/robots.txt 2>/dev/null; 
done < <(sed '/^$/d; s/^.*=//; s/ //g' INPUT_FILE|sed 'N;s/\n/ /')
  • Related