简体   繁体   中英

Print Multiple key value pair in single line using sed or awk

My input: ps -ef|grep mysql

    --defaults-file=/xyz/ --basedir=name --datadir=/data  --user=abc--log-error=/log1 --port=1211
    --defaults-file=/mno/ --basedir=anothername --datadir=/data2  --user=pqr --log-error=/log2 --port=1212

I tried following command

ps -ef|grep mysql| awk 'BEGIN {RS=" "}; /--port/' 
output:

--port=1211
--port=1212

How do i get specific key valur pair using a single awk command? Output should be like this

port:1211
base dir:name
log dir:log1

port:1212
base dir:anothername
log dir:log2

Not sure your sed version, try this:

sed -e '/port=/{' -e 'h;s/.*--port=\([0-9]*\)\s*$/port:\1/;x;s/.*--basedir=\([^ ]*\).*--log-error=.\([^ ]*\).*/base dir:\1\nlog dir:\2\n/;H;x}'

--posix tested working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM