rmyorston / busybox-w32

WIN32 native port of BusyBox.
https://frippery.org/busybox
Other
694 stars 126 forks source link

The sed command does not support piped output #311

Closed yyingc closed 1 year ago

yyingc commented 1 year ago

BusyBox v1.37.0-FRP-4882-g6e0a6b7e5 (2023-02-15 22:00:25 GMT) (mingw64-gcc 12.2.1-5.fc37; mingw64-crt 10.0.0-3.fc37; glob)

I am using in batch The latest version tag I use to get the resource %busybox% wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest"|%busybox% grep -i "tag_name"|!busybox! sed -r "s/tag_name//gI;s/[\":,]//g;s/[[:space:]]//g"|sort Error message: sed: bad option in substitution expression

%busybox% wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest"|%busybox% grep -i "tag_name"|!busybox! sed -r "s/tag_name//gI;s/[\":,]//g;s/[[:space:]]//g" >test.txt error

Or if you want to integrate the tr command

rmyorston commented 1 year ago

I think the problem is how to escape the double quote character in the sed substitution.

Try this: %busybox% wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest"|%busybox% grep -i "tag_name"|!busybox! sed -r "s/tag_name//gI;s/[\\":,]//g;s/[[:space:]]//g"|sort

Mixing cmd.exe and Unix shell syntax will, unfortunately, result in many problems like this.

yyingc commented 1 year ago

I think the problem is how to escape the double quote character in the sed substitution.

Try this: %busybox% wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest"|%busybox% grep -i "tag_name"|!busybox! sed -r "s/tag_name//gI;s/[\\":,]//g;s/[[:space:]]//g"|sort

Mixing cmd.exe and Unix shell syntax will, unfortunately, result in many problems like this.

I found out that the problem is the double quotes, but I need to remove the double quotes, this can not be solved s/[\\":,]//g

rmyorston commented 1 year ago

Sorry, try s/[\"":,]//g instead.

Alternatively put the commands in a shell script file (called release, for example):

#!/bin/sh

wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest" | \
    grep -i "tag_name" | \
    sed -r "s/tag_name//gI;s/[\":,]//g;s/[[:space:]]//g" | sort

and run it using %busybox% sh release.

yyingc commented 1 year ago

Sorry, try s/[\"":,]//g instead.

Alternatively put the commands in a shell script file (called release, for example):

#!/bin/sh

wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest" | \
  grep -i "tag_name" | \
  sed -r "s/tag_name//gI;s/[\":,]//g;s/[[:space:]]//g" | sort

and run it using %busybox% sh release.

for /f "delims=" %%v in ('%busybox% wget -q -O - "https://api.github.com/repos/fatedier/frp/releases/latest"^|%busybox% grep -i "tag_name"^|%busybox% sed -r "s/tag_name//gI;s/["":,]//g;s/[[:space:]]//g"') do (ECHO %%~v)

It worked, thank you very much for your patience.

yyingc commented 1 year ago

How to use %busybox% pipe_progress with wget command, I want to use progress bar

rmyorston commented 1 year ago

You just need to include %busybox% pipe_progress in the pipeline. It passes any data through to the next command and displays a '.' every second.

C:\Users\rmy>%busybox% wget -q -O - ftp://ftp.frippery.org/iso/bigfile.iso | %busybox% pipe_progress | %busybox% cat >bigfile.iso
..............................
C:\Users\rmy>
yyingc commented 1 year ago

You just need to include %busybox% pipe_progress in the pipeline. It passes any data through to the next command and displays a '.' every second.

C:\Users\rmy>%busybox% wget -q -O - ftp://ftp.frippery.org/iso/bigfile.iso | %busybox% pipe_progress | %busybox% cat >bigfile.iso
..............................
C:\Users\rmy>

Thank you. The problem has been resolved and we have successfully used it