bash / put a text file content in a variable

Hello guys,

I have a txt-file that has a (changing) number as content in it. ex: “12345”

I need to put this (changing) number in a variable. This number is filtered out of a html-page (with a sed-command).

Who can give me a tip?



(this is the script)


#!/bin/bash

wget nos.nl/uitzending/nos-journaal
grep ‘data-id=.*"’ nos-journaal > dataid.txt #get the data-id number
sed -i ‘s/data-id="//g’ dataid.txt #clean up the number, remove quotes and spaces and junk
sed -i ‘s/"//g’ dataid.txt #
sed -i ‘s/ //g’ dataid.txt #

#put the content of dataid.txt in a variable!
#replace year/month/day with variables!
#wget https://download.omroep.nl/nos/content/mp4/web03/2017/06/02/$dataid/mp4_web03.mp4

At the end i want to wget a mp4-file. I want to put the “number” in a variable ($dataid) and in the download path.

This will read dataid.txt to a variable MY_VAR:

#!/bin/bash

wget nos.nl/uitzending/nos-journaal
grep 'data-id=.*\"' nos-journaal > dataid.txt #get the data-id number
sed -i 's/data-id=\"//g' dataid.txt #clean up the number, remove quotes and spaces and junk
sed -i 's/\"//g' dataid.txt
sed -i 's/ //g' dataid.txt

MY_VAR=$(cat dataid.txt) # Load into variable

echo $MY_VAR # Print variable to screen

THNX!! Works…

My script:

#!/bin/bash
rm txt
rm nos

wget nos.nl/uitzending/nos-journaal
grep ‘data-id=.*"’ nos-journaal > dataid.txt
sed -i ‘s/data-id="//g’ dataid.txt
sed -i ‘s/"//g’ dataid.txt
sed -i ‘s/ //g’ dataid.txt
MY_VAR=$(cat dataid.txt) # Load into variable
MY_YEAR=$(date +’%Y’)
MY_MONTH=$(date +’%m’)
MY_DAY=$(date +’%d’)
clear
wget https://download.omroep.nl/nos/content/mp4/web01/$MY_YEAR/$MY_MONTH/$MY_DAY/$MY_$
wget https://download.omroep.nl/nos/content/mp4/web02/$MY_YEAR/$MY_MONTH/$MY_DAY/$MY_$
wget https://download.omroep.nl/nos/content/mp4/web03/$MY_YEAR/$MY_MONTH/$MY_DAY/$MY_$
mv mp4_web01.mp4 nos.mp4
mv mp4_web02.mp4 nos.mp4
mv mp4_web03.mp4 nos.mp4
rm nos-journaal
rm *txt
mv nos.mp4 /mnt/dietpi_userdata/Video/nos.avi
service minidlna restart

ps: i have to add a logic in the script that will check id web03 is present (and then wget it) or web02 or web01 (these are the same video’s but then in decreasing sharpness-order)