ChatGPT - script um channels.conf obsolete etc. zu löschen

  • Hallo Zusammen,


    ich habe wieder hunderte OBOLETE oder_alt Kanäle in der Channels.conf.
    da ich nicht der begnadete Scripter bin habe ich chatGPT mal gefragt.


    Ich finde die Antwort durchaus angemessen, werde ich sicherlich mit einer copy mal testen...

    VDR stop und wieder starten habe ich noch nicht drin...


    Viele Grüße,


    Günter



    ChatGPT 3.5


    I have a long text file called channels.conf. The file is on Linux with one entry per line. I need a programm for Linux Shell, which deletes every line, which contains a certain string. The list of strings to match is stored in file sample.list.


    ChatGPT

    You can achieve this using a combination of shell commands in a small script or a one-liner. One efficient way to do this is by using grep in combination with a loop or xargs. Below, I provide a simple script that reads each line from sample.list and then uses grep -v to filter out lines containing each string from channels.conf. The -v option in grep inverts the match, meaning it will select lines that do not match the given pattern.

    Here's a straightforward script to accomplish this:

    Code
    bash

    How to Use This Script

    1. Save the script to a file, for example, filter_lines.sh.
    2. Make it executable by running chmod +x filter_lines.sh in the terminal.
    3. Execute the script by running ./filter_lines.sh from the terminal in the directory where your channels.conf and sample.list files are located.

    Explanation

    • The script first creates a temporary file using mktemp, where it keeps the intermediate results of filtering.
    • It then enters a loop, reading each line from sample.list.
    • For each line read from sample.list, it uses grep -vF to filter out lines containing the string from the temporary file. The -F option treats the pattern as a fixed string, not a regular expression, which is generally safer and more efficient for this use case.
    • After processing all lines in sample.list, it moves the temporary file back to channels.conf, effectively updating it with the filtered content.

    Remember, this script directly modifies the original channels.conf file. If you want to keep the original file unchanged, you can modify the last line of the script to move the temporary file to a new file instead.

    Ubuntu 22.04; Kernel 6.2.0-26; mit Parallelbetrieb von:
    VDR 2.6.4 über S2-6400 (HDMI1)
    XBMC /Kodi & Unity Desktop über Onboard Grafik (HDMI2)
    Beides an Sony KDL-55EX725
    Harmony-Hub zum Umschalten zwischen VDR und XBMC

    Einmal editiert, zuletzt von beachboy ()

  • Hier die nächste Version mit VDR Stop und Start...


    Wenn VDR über Systemd verwaltet wird, könnten die Befehle zum Starten und Stoppen systemctl start vdr und systemctl stop vdr sein. Hier ist das angepasste Skript:

    Ubuntu 22.04; Kernel 6.2.0-26; mit Parallelbetrieb von:
    VDR 2.6.4 über S2-6400 (HDMI1)
    XBMC /Kodi & Unity Desktop über Onboard Grafik (HDMI2)
    Beides an Sony KDL-55EX725
    Harmony-Hub zum Umschalten zwischen VDR und XBMC

  • Update:
    Ich habe die Aufgabe so gestellt, dass in sample.list nur ein keyword zum matchen drin ist.
    das ist natürlich blöd, es muss auch mehrere keywords enthalten können.
    Also, wieder etwas angepasst:


    If your sample.list contains several keywords, each on a new line, and you want to remove lines from channels.conf that match any of those keywords, the approach in the script I provided earlier works well for this scenario. Each line in sample.list is treated as a separate string to match against channels.conf. The script reads sample.list line by line and uses grep to filter out lines containing each keyword from channels.conf.

    To clarify how it handles multiple keywords, here’s a quick breakdown:

    1. The script reads sample.list one line (keyword) at a time.
    2. For each keyword, it uses grep -vF to filter out lines in channels.conf (or a temporary file during processing) that contain the keyword. The -v flag inverts the match, so grep selects lines that do not contain the keyword. The -F flag treats the pattern as a fixed string, not a regular expression.
    3. It repeats this process for each keyword in sample.list.

    Here’s the full script again for convenience, including stopping and starting VDR before and after processing:

    Ubuntu 22.04; Kernel 6.2.0-26; mit Parallelbetrieb von:
    VDR 2.6.4 über S2-6400 (HDMI1)
    XBMC /Kodi & Unity Desktop über Onboard Grafik (HDMI2)
    Beides an Sony KDL-55EX725
    Harmony-Hub zum Umschalten zwischen VDR und XBMC

  • Hmm, sowas braucht keine AI. Da gab es schon einen Thread https://www.vdr-portal.de/foru…ight=OBSOLETE#post1336115 dazu.

    Das Standard-Script war das unten - bitte ".txt" in ".sh" umbenennen und kontrollieren.

    Ich habe dann noch modifiziert und lasse das alle paar Tage/jede Woche laufen.

    Dateien

  • Hier mein Stand:
    https://github.com/MegaV0lt/VD…cal/sbin/cleanchannels.sh


    Start am besten vor dem VDR

  • Stimmt, hatte leider den Thread nicht gefunden, aber jetzt wo Du es erwähnst

    kommt es mir in den Sinn, dass ich das schon Mal gesehen hatte.


    Da ich mir überlege auf diese Art auch andere Channels aus der Liste zu werfen
    ist mir mein Ansatz mit einer beliebigen keywort-Liste lieber.
    Also z.B. fliegt bei mir in Zukunft der ganze Schmutzkram raus...

    Bei mir gibt es übrigens jetzt schon zwei Keywörter: obsolete und _alt

    Gruss,

    Günter

    PS: Übrigens braucht es für sowas nie AI, wenn man es kann ;)
    Nur bei mir geht es mit schneller ;)

    Ubuntu 22.04; Kernel 6.2.0-26; mit Parallelbetrieb von:
    VDR 2.6.4 über S2-6400 (HDMI1)
    XBMC /Kodi & Unity Desktop über Onboard Grafik (HDMI2)
    Beides an Sony KDL-55EX725
    Harmony-Hub zum Umschalten zwischen VDR und XBMC

  • Mein "Minimalskript" für sowas sieht so aus:

    Code
    grep --invert-match " OBSOLETE;" channels.conf > channels.new

    (Über die Jahre haben sich bei mir übrigens einige solche nützlichen Schnipsel gesammelt, mit denen man fast alles gelöst bekommt.)


    Das kann man auch ganz gut um weitere Befehle erweitern:

    Code
    grep --invert-match " OBSOLETE;" channels.conf > channels.new && mv -f channels.conf channels.save && mv channels.new channels.conf


    Grep kann die Suchmuster übrigens auch aus einer Datei einlesen.

    Die gewünschte Funktionalität ist also auch mit dem Einzeiler zu erlefüllen.

    (Bei vielen Suchmustern und großen Dateien ist das unter Umständen auch deutlich effizienter.)

    Code
    grep --invert-match -f channel_remove.txt channels.conf > channels.new 
    Code: channels_remove.txt
     OBSOLETE;
    ^.;
    _alt
    ^TEST

    Gruss
    SHF


  • Das kann man auch ganz gut um weitere Befehle erweitern:
    Code
    grep --invert-match " OBSOLETE;" channels.conf > channels.new && mv -f channels.conf channels.save && mv channels.new channels.conf

    In dem Fall kann einem sed viel Arbeit abnehmen:

    Code
    sed -i.backup '/ OBSOLETE;/d' channels.conf

    yaVDR-Dokumentation (Ceterum censeo enchiridia esse lectitanda.)

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!