문자열로 텍스트 인쇄

문자열로 텍스트 인쇄

이 출력은 cassandra-cli의 텍스트 파일로 표시됩니다. 인쇄해야 해서 RowKey사용 OnlineUsers하고 있어요세게 때리다, 그리고 grep작동하지 않습니다.

Column Family assumptions read from /root/.cassandra/assumptions.json
Welcome to Cassandra CLI version 1.2.19

Type 'help;' or '?' for help.
Type 'quit;' or 'exit;' to quit.

[default@unknown] use Agent;
Authenticated to keyspace: Agent
[default@Agent] list VCCs;
Using default limit of 100
Using default cell limit of 100
-------------------
RowKey: cienciaactiva
=> (name=AllegroIntegration, value={"enabled":true}, timestamp=1504725823694867)
=> (name=CALL_licensed, value=1, timestamp=1504725823700706)
=> (name=CHAT_licensed, value=1, timestamp=1504725823695468)
=> (name=Id, value=cienciaactiva, timestamp=1504725823696915)
=> (name=IsSystemVCC, value=0, timestamp=1504725823699902)
=> (name=MAIL_licensed, value=1, timestamp=1504725823699520)
=> (name=OnlineUsers, value=1, timestamp=1504725823698413)
=> (name=WEBCONTACT_licensed, value=1, timestamp=1504725823697610)
-------------------
RowKey: atento
=> (name=CHAT_licensed, value=0, timestamp=1459855264796678)
=> (name=Id, value=atentoperusedapal, timestamp=1459855264801483)
=> (name=IsSystemVCC, value=1, timestamp=1459855264802006)
=> (name=MAIL_licensed, value=0, timestamp=1459855264797787)
=> (name=OnlineUsers, value=5, timestamp=1459855264796155)
=> (name=WEBCONTACT_licensed, value=0, timestamp=1459855264803923)
-------------------
RowKey: tsc
=> (name=CHAT_licensed, value=0, timestamp=1464217813009934)
=> (name=Id, value=tsc, timestamp=1464217813012789)
=> (name=IsSystemVCC, value=1, timestamp=1464217813016091)
=> (name=MAIL_licensed, value=1, timestamp=1464217813010988)
=> (name=OnlineUsers, value=7, timestamp=1485884014708000)
=> (name=WEBCONTACT_licensed, value=0, timestamp=1464217813012116)

3 Rows Returned.
Elapsed time: 178 msec(s).
[default@Agent]

예상되는 출력은 다음과 유사합니다.

RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7

답변1

그리고awk주문하다:

awk '/RowKey/; /name=OnlineUsers/{ 
        print substr($2, 2), substr($3, 1, length($3)-1); f=1 
     }f && /---/' file

산출:

RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7

답변2

grep이 목적에 적합해야 합니다:

$ grep -e '^RowKey:' -e name=OnlineUsers -e '^----' input
-------------------
RowKey: cienciaactiva
=> (name=OnlineUsers, value=1, timestamp=1504725823698413)
-------------------
RowKey: atento
=> (name=OnlineUsers, value=5, timestamp=1459855264796155)
-------------------
RowKey: tsc
=> (name=OnlineUsers, value=7, timestamp=1485884014708000)

타임스탬프를 제거해야 한다면 OnlineUsersGNU를 사용하여 쉽게 제거할 수 있습니다 awk.

$ awk -F '[(,]' '/^RowKey:/ || /^----/ { print } /name=OnlineUsers/ { print $2 "," $3 }' input
-------------------
RowKey: cienciaactiva
name=OnlineUsers, value=1
-------------------
RowKey: atento
name=OnlineUsers, value=5
-------------------
RowKey: tsc
name=OnlineUsers, value=7

관련 정보