Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Busybox 环境下貌似不支持 grep -Po 这个命令,如何改呢 #21

Open
matthuo333 opened this issue Apr 1, 2022 · 1 comment

Comments

@matthuo333
Copy link

在脚本中有如下:
grep -Po '(?<="id":")[^"]*' | head -1 )

但是我当前环境是 BusyBox v1.24.1,貌似不支持这个 -- ‘P’的参数, 如何修改呢?

当前执行后报错:
No file, need IP
Updating zone_identifier & record_identifier
grep: invalid option -- 'P'
BusyBox v1.24.1 (2022-03-24 03:19:19 CST) multi-call binary.

Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

-H	Add 'filename:' prefix
-h	Do not add 'filename:' prefix
-n	Add 'line_no:' prefix
-l	Show only names of files that match
-L	Show only names of files that don't match
-c	Show only count of matching lines
-o	Show only the matching part of line
-q	Quiet. Return 0 if PATTERN is found, 1 otherwise
-v	Select non-matching lines
-s	Suppress open and read errors
-r	Recurse
-i	Ignore case
-w	Match whole words only
-x	Match whole lines only
-F	PATTERN is a literal (not regexp)
-E	PATTERN is an extended regexp
-m N	Match up to N times per file
-A N	Print N lines of trailing context
-B N	Print N lines of leading context
-C N	Same as '-A N -B N'
-e PTRN	Pattern to match
-f FILE	Read pattern from file

(23) Failed writing body

@CraKeyBoy
Copy link

CraKeyBoy commented Aug 13, 2022

可以以下命令替代:

 | grep -o '"id":"[^"]*' | grep -o '[^"]*$' | head -1

参考:
https://stackoverflow.com/questions/36073695/how-to-retrieve-single-value-with-grep-from-json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants