0

I have a file (userbouquet.test.tv) 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.

EDiT 1: only lines that begin with string #SERVICE and end with ":" (example #SERVICE 1:0:1:64:1:5E:30B022:0:0:0:)
The lines that begin with string #SERVICE but end with a text (comment) should also be ignored (example #SERVICE 1:64:5:0:0:0:0:0:0:0::PVU 12322 V 27500 5-6)

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 
2
  • What is the relationship between the provided file and userbouquet.test.tv? The same file? Commented Jan 8, 2022 at 1:10
  • yes, that is the content of the userbouquet.test.tv file Commented Jan 8, 2022 at 11:28

2 Answers 2

1
#!/bin/bash

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

while read -u3 a b _; do
    if [[ $a == '#SERVICE' && $b == *: ]]; then
        wget -q -O - "http://127.0.0.1/web/zap?sRef=$b"
        sleep 3
    fi
done 3< "$userbouquet"
Sign up to request clarification or add additional context in comments.

7 Comments

Nice answer, but it will contain PVU at the end of $b in some lines. I'm afraid it differs from the OP's desired example...
@tshiono He only needs lines starting with #SERVICE.
If he wants PVU excluded, he should mention.
Right. I just noticed the OP's description for example 1:64:5:0:0:0:0:0:0:0::. He/she can solve it according to your comment anyway.
Working as requested. Excellent. Thank you.
|
1

Some of the lines in the input example provided end with whitespace, so the awk pattern contains [[:space:]]* between : and $ (end of line).

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

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

2 Comments

Good call with awk but you should use quotes when expanding a variable and potential glob characters like ? => "http://127.0.0.1/web/zap?sRef=$variable"
This script unfortunately is not working. It's stuck. I added line echo variable= $variable but there is still no output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.