Migrating Bash Script Functionality To Powershell

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

 

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? :wink:

Um, hey look. This is the answer.

'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

Output:

2
3

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.

 

[quote quote=178683]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
[/quote]

Thanks js! - really appreciate your help.