Script reading from file and send to firefox


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script reading from file and send to firefox
# 1  
Old 02-27-2013
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:
Code:
server1.com : google,yahoo,alex,cnn

server2.com : resdf,walsdfa,yndf,asdf

server3.com : icqsdf,ebasdf,asdfmon

the script named dx.sh contains:
Code:
#! /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

Last edited by vbe; 02-27-2013 at 12:45 PM.. Reason: code tags!!
# 2  
Old 02-27-2013
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:
Code:
#!/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.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 02-27-2013
how can i write the output to a file?? and not to the screen?

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

the ouptut looks like this:
firefox http://google&2Cyahoo&2Calex&2Ccnn&2...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:
Code:
#!/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


Last edited by zigizag; 02-27-2013 at 05:18 PM.. Reason: Please use code tags...
# 4  
Old 02-27-2013
Please always wrap code fragments or data samples in code tags

Here is modified code that redirects output to file: output.txt
Code:
#!/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

This User Gave Thanks to Yoda For This Post:
# 5  
Old 02-28-2013
wow!! thanks alot!!

Quote:
Originally Posted by bipinajith
Please always wrap code fragments or data samples in code tags

Here is modified code that redirects output to file: output.txt
Code:
#!/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

---------- 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!!
# 6  
Old 02-28-2013
Try:
Code:
[[ "$line" =~ ^\*[[:blank:]]server1.com ]] && url_s1=${line##*: }
[[ "$line" =~ ^\*[[:blank:]]server2.com ]] && url_s1=${line##*: }
[[ "$line" =~ ^\*[[:blank:]]server3.com ]] && url_s1=${line##*: }

This User Gave Thanks to Yoda For This Post:
# 7  
Old 02-28-2013
Hi

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

10x!!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Reading Array And Send An Email

I am trying to find an example for reading an array instead of reading a file and send out an email in ksh. Can you please help is that possible? Algorithm #!/bin/ksh i=0 set -A ARR if then let i=$ ARR="A does n't match with B" fi if then let i=$ ARR="P does n't match with Q"... (11 Replies)
Discussion started by: Ariean
11 Replies

4. Shell Programming and Scripting

Bash script to send lines of file to new file based on Regex

I have a file that looks like this: cat includes CORP-CRASHTEST-BU e:\crashplan\ CORP-TEST /usr/openv/java /usr/openv/logs /usr/openv/man CORP-LABS_TEST /usr/openv/java /usr/openv/logs /usr/openv/man What I want to do is make three new files with just those selections. So the three... (4 Replies)
Discussion started by: newbie2010
4 Replies

5. UNIX for Dummies Questions & Answers

UNIX script for reading a file and creating another file

Hi, I am a beginner in scripting...I have to do a script where I have to read a file which has list of job names, line by line and for every line execute a dsjob command to find the log details of the job and extract only the start time of the job, if it is greater than jan 01 2008 and create... (1 Reply)
Discussion started by: Vijay81
1 Replies

6. Shell Programming and Scripting

Reading Delimited file and send mail with attachment

Hi All, My requirement is: 1. To read a file that contains log file location and server name. The format of the file is something like this : server_name1:logfilename1 server_name2:logfilename2 2. Now I wants to grep "error" string from the logfilename and put it into another file for... (3 Replies)
Discussion started by: acheiver
3 Replies

7. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

8. UNIX for Dummies Questions & Answers

script to reading a file

hi, I have a file containing names, say n number of names, sample file robin smith dallas frey cook all these names are in a file name called names.txt and it is placed in a directory called /data/names all i want is to write a script, which will read from the file and gives the... (3 Replies)
Discussion started by: vasikaran
3 Replies

9. Programming

Reading a file into a C++ script

Hi, I'm trying to read a file in with and assigne the stream to a char * type. I've manged it using the cin.get returning type char, but am having run-time problems returning a char *. For example, char *pStream = "file.txt"; ifstream from(pStream); from.open(pStream); ... (1 Reply)
Discussion started by: Breen
1 Replies
Login or Register to Ask a Question