Solved

how to get a informatin on a text files for my script

Posted on 2014-10-07
8
146 Views
Last Modified: 2014-10-08
Hello

is a script bash

my part of code
 -v -T '848444' -r "link1" -a "link2" -f "WIN 13,0,0,182" -W "yes.swf" -p "http://yoyo.com" -y "mp4:$src" -o "$name.mp4"

Open in new window


exemple text files
<meta base="link.com/blablabla.mp4"/></head><body><video src="link.com/blablabla" /></body>

Open in new window


I want to get the links between "" "" and copy to my code

exemple 2
get this link on the text files  "link.com/blablabla.mp4" (link 1)  "link.com/blablabla"  (link 2)

-v -T '848444' -r "link.com/blablabla.mp4" -a "link.com/blablabla" -f "WIN 13,0,0,182" -W "yes.swf" -p "http://yoyo.com" -y "mp4:$src" -o "$name.mp4"

Open in new window


and copie link on my code  without the "

tx :)
0
Comment
Question by:Gaaara
  • 4
  • 3
8 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 40367653
In the first example, where is the text file referenced?

In the second example, are links defined by the -a and -r arguments?
0
 

Author Comment

by:Gaaara
ID: 40367663
my code is an  example purposes only

I want to have that in between " " and copy in a  variable on my bash :)

exemple

is the text files

<meta base="link.com/blablabla.mp4"/></head><body><video src="link.com/blablabla" /></body> 

Open in new window


how to get information between " " on text files

and créate a variable on my bash

link1=link.com/blablabla.mp4
echo "$link1" 

link2=link.com/blablabla
echo "$link2"

Open in new window

0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40367994
Are there always exactly two quoted strings in the relevant line of the text file?
Do these lines always contain a unique keyword, like e. g. "meta"?
And, most important: Is there just one line in the textfile containing that keyword?

If so you can try this:

links=$(sed  -n '/meta/s/^.*"\(.*\)".*"\(.*\)".*$/\1 \2/p' textfile)
link1=${links% *}
link2=${links#* }
echo $link1
echo $link2

Alternatively, use awk. This will work even if there is just one quoted string, but we'll need a check to avoid link1 and link2 being the same in that case:

links=$(awk -F\" '/meta/ {if($4=="") $4="dummy"; print $2, $4}' textfile)
link1=${links% *}
link2=${links#* }
[[ $link2 = "dummy" ]] && unset link2
echo $link1
echo $link2

If there are (can be) several lines in the textfile containing the keyword and the links we must create a loop and work with arrays instead of single variables.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:Gaaara
ID: 40368808
did not work

Are there always exactly two quoted strings in the relevant line of the text file?  yes
Do these lines always contain a unique keyword, like e. g. "meta"? yes
And, most important: Is there just one line in the textfile containing that keyword? no

links always changes just some word that does not change
link1 rtmpe: // does not change
link2 mp4 does not change

<smil><head><meta base="rtmpe://yoyo.com/vod"/></head><body><video src="JPMAK9ytVw3fzAxHuweyyeuw3743434kn3j4huyd67cuj3nr$$%fjudfyDWIe9XM2BElbQ74JZnAHm5RYe3EUm5J9AmZdpeJdK78VaGdw%3D-p%2BdQbrgVg7oqPMKmM16KQw%3D%3D.mp4?audioindex=0" /></body></smil>
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40368946
Given the data you posted both of my scripts will show

for link1:
rtmpe://yoyo.com/vod

for link2:
PMAK9ytVw3fzAxHuweyyeuw3743434kn3j4huyd67cuj3nr$$%fjudfyDWIe9XM2BElbQ74JZnAHm5RYe3EUm5J9AmZdpeJdK78VaGdw%3D-p%2BdQbrgVg7oqPMKmM16KQw%3D%3D.mp4?audioindex=0

which exactly represents the two quoted strings which you asked to extract.

So why do you say "did not work" (apart from the fact that such a phrase is rude, at least extremely impolite)?
0
 

Author Comment

by:Gaaara
ID: 40369010
im so sorry ! it works

sorry I do not mean to be rude and it works I had made ​​a mistake

is a google translate and I do not speak english naturally
0
 

Author Closing Comment

by:Gaaara
ID: 40369012
nikel
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40369052
Merci a la pelle!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question