[LINUX] sed memo

--Confirmation environment: sed (GNU sed) 4.2.2 --There are parts that behave differently from regular expressions in PHP, JavaScript, and VSCode. ――In conclusion, I think you can't do anything that isn't written in the sed manual. ――The regular expression engine I'm used to is Oniguruma, so it feels strange.

Replacement method

Basic

--s / represents permutation --sed's / search character / replacement character /'

Expansion

--When you want to capture -r --When using capture, \ sed -r's / search (character) / \ 1 /'

Unique habit

--Basically, there is a habit around capture --\ s cannot be used[\ t \ n \ v \ f \ r \ x20]can be used instead

Part 1

--I have a habit of capturing (Is the behavior of ? Different?) --When you do /.+?"Records ":" (. +?) ". + / To the following text, PHP, JS, VSCode will cost $ 1 ʻa @ 163.43.80.45 \ nmx @ 10 \ ntxt .... can be captured --sed -r's /. +?" Records ":" (. +?) ". + / \ 1 /' ʻa @ 163.43.80.45 \ nmx @ 10 \ ntxt .... "," ttl ":" 60 "}," request_id ":" 202010191733159039640087223V "," request ": {"path ":" /v1/domains/example.com/dns "," method ":" GET "," params Become --You need to do sed -r's /. +?" Records ":" ([^ "] +?)". + / \ 1 /' to get the expected result.

{"results":{"domainid":6526946,"domainname":"example.com","ns_type":"foobarbaz","records":"a @ 163.43.80.45\nmx @ 10\ntxt ....","ttl":"60"},"request_id":"202010191733159039640087223V","request":{"path":"/v1/domains/example.com/dns","method":"GET","params":[]}}

Part 2

――After all there is a habit of capturing --When you do / ^ (?: [^] +? +?) {3} ([^] +). + / For the following text, in PHP, JS, VSCode, it is $ 1 and 1.0 Can be captured --sed -r's / ^ (?: [^] +? +?) {3} ([^] +). + / \ 1 /' gives the following error sed: -e expression # 1, char 33: Invalid preceding regular expression --You need to use sed -r's / ^ ([^] +? +?) {3} ([^] +). + / \ 2 /' to get the expected result. --Maybe you can't use ?: (I think you can't use non-capturing group in sed)

root      51849  0.0  1.0   7488   812 ?        Sl   Oct16   0:52 docker-containerd-shim

Recommended Posts

sed memo
gzip memo
Raspberry-pi memo
Pandas memo
HackerRank memo
Python memo
python memo
graphene memo
Flask memo
pyenv memo
Matplotlib memo
pytest memo
Python memo
Install Memo
BeautifulSoup4 memo
networkx memo
sed command
python memo
tomcat memo
command memo
Generator memo.
psycopg2 memo
Python memo
SSH memo
Command memo
Memo: rtl8812
pandas memo
Shell memo
Python memo
Pycharm memo
Python memo
AtCoder devotion memo (11/12)
[OpenCV] Personal memo
[Python] Memo dictionary
PyPI push memo
tensorflow-gpu introduction memo
LPIC201 learning memo
Jupyter Notebook memo
LPIC304 virtualization memo
ALDA execution memo
youtube download memo
Memorandum of sed
ARC # 016 Participation memo
Beautiful Soup memo
LPIC101 study memo
python beginner memo (9.1)
linux (ubuntu) memo
scp command memo
Flask Primer Memo
celery / kombu memo
who command memo
django tutorial memo
Flask basic memo
Linux # Command Memo 1
★ Memo ★ Python Iroha
Gender recognition memo
Image reading memo
[MEMO] [TERMINAL] Alacritty
3D rotation memo (1)
[Python] EDA memo
Python 3 operator memo