Migrating Bash Script Functionality To Powershell

Welcome Forums General PowerShell Q&A Migrating Bash Script Functionality To Powershell

Viewing 3 reply threads
  • Author
    Posts
    • #178638
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Hi guys – I’m looking to create a script that runs when using Transmission torrent client on Windows.

      The script runs after something has downloaded and removes any completed downloads from the queue automatically.

      Currently there is already a bash script available for Linux users, I’d like to provide the same functionality with Powershell.

      Here’s the bash script https://pastebin.com/0neMUeKX

      I’m struggling to get similar functionality with powershell mostly with the following line:-

      sed -e ‘1d’ -e ‘$d’ | awk ‘{print $1}’ | sed -e ‘s/[^0-9]*//g’`

      Anyone with better knowledge of Powershell who could assist would be greatly appreciated!

      Many thanks

       

    • #178671
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      As bash code is everything else than descriptive I could imagine that not all of us Powershellers can read and understand bash code. Why don’t you describe what your bash code is supposed to do and we might be able to recommend what Powershell equivalent you could use? 😉

      • #178689
        Participant
        Topics: 1
        Replies: 2
        Points: 17
        Rank: Member

        The comments in the script outline what the function is.  Essentially it calls transmission-remote to list current torrents, check if they are currently downloading and purge from the list if completed.

         

    • #178683
      js
      Participant
      Topics: 32
      Replies: 842
      Points: 2,686
      Helping Hand
      Rank: Community Hero

      Um, hey look. This is the answer.

      Output:

    • #178749
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Um, hey look. This is the answer.

      PowerShell
      11 lines

      <textarea class=”ace_text-input” style=”opacity: 0; height: 18px; width: 6.59781px; left: 51px; top: 0px;” spellcheck=”false” wrap=”off”></textarea>

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      ‘1first line’,‘2second line’,‘3third line’,‘4fourth line’ |
      # sed -e ‘1d’ -e ‘$d’ |
      select skip 1 | select skiplast 1 | # delete first and last line
      # awk ‘{print $1}’ |
      foreach { (-split $_)[0] } | # split line and take only first field
      # sed -e ‘s/[^0-9]*//g’`
      foreach { $_ -replace ‘[^0-9]*’ } # delete all non-nummbers
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Output:

      PowerShell
      3 lines

      <textarea class=”ace_text-input” style=”opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;” spellcheck=”false” wrap=”off”></textarea>

      1
      2
      3
      2
      3
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Thanks js! – really appreciate your help.

Viewing 3 reply threads
  • The topic ‘Migrating Bash Script Functionality To Powershell’ is closed to new replies.