Script reading from file and send to firefox

Hi everbody,

i have a little problem.
i want to know how can i read from a txt file parametes and send it to a firefox http link.

all that in shell script
EXAMPLE-

the file 1.txt contains:

server1.com : google,yahoo,alex,cnn

server2.com : resdf,walsdfa,yndf,asdf

server3.com : icqsdf,ebasdf,asdfmon

the script named dx.sh contains:

#! /bin/bash

firefox 'http://server1 &2C.com' ' 'http://server2 &2C.com' ' 'http://server3 &2C.com'

#every parameter on each server should be seperated. like 'http://server1 google&2Cyahoo&2Calex&2Ccnn.com' and shold also be seperated by &2C

Thanks!!

every time i run the script it should read from the file parameters from every line/server and put it in its own http tab.

i have

To give you an idea, here is a script that

  1. Read from file: 1.txt

  2. Check if the entry corresponds to server1.com

  3. Print each URLs:

#!/bin/bash

while read line
do
        [[ "$line" =~ ^server1.com ]] && url=${line##*: }

done < 1.txt

for U in ${url//,/ }
do
        printf "http://$U.com\n"
done

Modify as per your requirement.

1 Like

still how can i write the output of it to a file?

the ouptut looks like this:
firefox http://google&2Cyahoo&2Calex&2Ccnn&2Csdsd&2CCersdfsdf&2CSDFSDF&2C.com/index.html
firefox http://resdf&2Cwalsdfa&2Cyndf&2Casdf&2C.com/index.html
firefox http://icqsdf&2Cebasdf&2Casdfmon&2C.com/index.htm
10x to bipinajith the new code is:

#!/bin/bash

echo -n "firefox http://"
while read line
do
        [[ "$line" =~ ^server1.com ]] && url=${line##*: }

done < 1.txt

for U in ${url//,/ }
do
        printf "$U&2C"
done

echo -n ".com/index.html"
echo -e
echo -n "firefox http://"
while read line
do
        [[ "$line" =~ ^server2.com ]] && url=${line##*: }

done < 1.txt

for U in ${url//,/ }
do
        printf "$U&2C" 
done

echo -n ".com/index.html"
echo -e

echo -n "firefox http://"
while read line
do
        [[ "$line" =~ ^server3.com ]] && url=${line##*: }

done < 1.txt

for U in ${url//,/ }
do
        printf "$U&2C"
done
echo -n ".com/index.html"
echo -e

Please always wrap code fragments or data samples in code tags

Here is modified code that redirects output to file: output.txt

#!/bin/bash

while read line
do
        [[ "$line" =~ ^server1.com ]] && url_s1=${line##*: }
        [[ "$line" =~ ^server2.com ]] && url_s2=${line##*: }
        [[ "$line" =~ ^server3.com ]] && url_s3=${line##*: }
done < 1.txt

{
        echo -n "firefox http://"
        for U in ${url_s1//,/ }
        do
                printf "${U}&2C"
        done
        echo ".com/index.html"

        echo -n "firefox http://"
        for U in ${url_s2//,/ }
        do
                printf "${U}&2C"
        done
        echo ".com/index.html"

        echo -n "firefox http://"
        for U in ${url_s3//,/ }
        do
                printf "${U}&2C"
        done
        echo ".com/index.html"
} > output.txt
1 Like

---------- Post updated at 04:11 PM ---------- Previous update was at 03:59 PM ----------

thanks alot!! excellent!!

---------- Post updated 02-28-13 at 01:36 AM ---------- Previous update was 02-27-13 at 04:11 PM ----------

the thung is that i changed the txt file instead of:

server1.com : wer,wer,we

server2.com : wer,wer,we

server3.com : wer,wer,we

the new one is:

  • server1.com : wer,wer,we
    ------------------------------
  • server2.com : wer,wer,we
    ------------------------------
  • server3.com : wer,wer,we
    -------------------------------

does any body know what shoukd i change in the code??

thanks!!

Try:

[[ "$line" =~ ^\*[[:blank:]]server1.com ]] && url_s1=${line##*: }
[[ "$line" =~ ^\*[[:blank:]]server2.com ]] && url_s1=${line##*: }
[[ "$line" =~ ^\*[[:blank:]]server3.com ]] && url_s1=${line##*: }
1 Like

Hi

i am sorry but it didnt work .maybe i did something wrong?

10x!!

Make sure you have each line starting with an asterisk * and not any other character.

Also put an asterisk after character class [[:blank:]] to check zero or more occurrence:

[[ "$line" =~ ^\*[[:blank:]]*server1.com ]] && url_s1=${line##*: }
1 Like

sorry didnt work. can you please test it?

10x again!!

It works for me!

It should be something to do with your input file. Can you post few lines from your original input file in code tags ?

1 Like

my 1.txt file looks like this exactly:

while read line
do
        [[ "$line" =~ ^\*[[:blank:]]*server1.ux.com ]] && url_s1=${line##*: }
        [[ "$line" =~ ^\*[[:blank:]]*server2.ux.com ]] && url_s2=${line##*: }
        [[ "$line" =~ ^\*[[:blank:]]*server3.ux.com ]] && url_s3=${line##*: }
done < 1.txt

{
        echo -n "firefox http://"
        for U in ${url_s1//,/ }
        do
                printf "${U}&2C"
        done
        echo ".com/index.html"

        echo -n "firefox http://"
        for U in ${url_s2//,/ }
        do
                printf "${U}&2C"
        done
        echo ".com/index.html"

        echo -n "firefox http://"
        for U in ${url_s3//,/ }
        do
                printf "${U}&2C"
        done
        echo ".com/index.html"
} > output2.txt

---------- Post updated at 09:55 AM ---------- Previous update was at 09:46 AM ----------

can you try it?

OK, if this is your input file then simply match urls. Replace existing with:

while read line
do
        [[ "$line" =~ server1\.ux\.com ]] && url_s1=${line##*: }
        [[ "$line" =~ server2\.ux\.com ]] && url_s2=${line##*: }
        [[ "$line" =~ server3\.ux\.com ]] && url_s3=${line##*: }
done < 1.txt
1 Like