Home > Mobile >  Bash script to assign some data from a file to variables
Bash script to assign some data from a file to variables

Time:01-08

I have a file with the following format:

#NAME 4.8E-Astra  
#SERVICE 1:64:5:0:0:0:0:0:0:0::PVU 12322 V 27500 5-6  
#DESCRIPTION PVU 12322 V 27500 5-6  
#SERVICE 1:0:1:64:1:5E:30B022:0:0:0:  
#SERVICE 1:0:1:190:1:5E:30B022:0:0:0:  
#SERVICE 1:64:6:0:0:0:0:0:0:0::PVU 12360 V 27500 5-6  
#DESCRIPTION PVU 12360 V 27500 5-6  
#SERVICE 1:0:1:258:1:5E:300000:0:0:0:

Could you help me with one script that reads each line and check if line begins with string #SERVICE.
If line begins with string #SERVICE then to assign the coresponding value (for example 1:64:5:0:0:0:0:0:0:0::) into a variable.

I managed to writte the following:

#!/bin/bash  
userbouquet="/etc/enigma2/userbouquet.test.tv"  
for (( i=1; i<=$(grep "" -c $userbouquet); i   ))  
do   
#
# HELP ME HERE
#
wget -q -O - http://127.0.0.1/web/zap?sRef={variable}
#example wget -q -O - http://127.0.0.1/web/zap?sRef=1:64:5:0:0:0:0:0:0:0::
sleep 3s  
done 

CodePudding user response:

#!/bin/bash
userbouquet="/etc/enigma2/userbouquet.test.tv"

for variable in $(awk '/#SERVICE/ {print $2}' $userbouqet); do
    wget -q -O - http://127.0.0.1/web/zap?sRef=$variable
    sleep 3s  
done

CodePudding user response:

#!/bin/bash

userbouquet="/etc/enigma2/userbouquet.test.tv"

while read -u3 a b _; do
    if [[ $a == '#SERVICE' ]]; then
        wget -q -O - "http://127.0.0.1/web/zap?sRef=$b"
        sleep 3
    fi
done 3< "$userbouquet"

If PVU needs to be stripped out, change $b to ${b%PVU}.

  •  Tags:  
  • Related